'MacroName:UCSD_BatchControlReport1902!ReportHeadingsOnly ' 'MIT License ' 'Copyright (c) 2019 UC San Diego Library ' 'Permission is hereby granted, free of charge, to any person obtaining a copy 'of this software and associated documentation files (the "Software"), to deal 'in the Software without restriction, including without limitation the rights 'to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 'copies of the Software, and to permit persons to whom the Software is 'furnished to do so, subject to the following conditions: ' 'The above copyright notice and this permission notice shall be included in all 'copies or substantial portions of the Software. ' 'THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 'IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 'FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 'AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 'LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 'OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 'SOFTWARE. ' ' 'MacroDescription: Macro will work through consecutively-numbered items in a save file and control all headings, and then check for 1XX, 6XX, 7XX and 8XX fields that ' are still not controlled and write the uncontrolled headings to desktop file, ControlledHeadingsReport.tsv, a tab-separated file that can be viewed as a text file ' or opened as a spreadsheet to view and manipulate the report. Multiple uncontrolled terms in a single record will report in a single tab-separated block, with the ' individual fields separated in the block by pipes ("|"). These can be used to further separate the cell in Excel if desired. 'When working with very large files the variable Looper can be set to begin part-way into the file, and the file can be set to work up to a certain line number by ' removing the commented-out limit indicated below. 'NOTE: A tic in the OCLC OML macro language extension to MARC apprently can't tell if a geographic heading or heading component is controlled, so a record with geographic ' components will mis-report as not controlled even if it is fully controlled. 'Macro originally coded by Jim Soe Nyun June 28, 2018 'This version comments out the line that controls headings. This significantly speeds up the processing time and is useful if this is run after the Ubermacro or other ' process that may have already attempted to control controllable headings. That procedure may be reinstated by removing the single quote mark preceding ' the line below with the command "' CS.ControlHeadingsAll" Option explicit Declare Sub ReportUncontrolledHeadings(FieldsToReport$) Dim CS As Object '********************************************** Sub Main On Error GoTo EndMacro Dim Looper%,Recordcounter%,FieldsToReport$,user$ Looper=1 Recordcounter=1 Set CS = CreateObject("Connex.Client") user = Environ("username") Open "C:\users\" & user & "\desktop\ControlledHeadingsReport.tsv" For Append As #1 Write #1, "**********************************" & now & "**********************************" Write #1, "SAVE FILE #" & Chr(34) & Chr(9) & Chr(34) & "OCLC #" & Chr(34) & Chr(9) & Chr(34) & "TITLE" & Chr(34) & Chr(9) & Chr(34) & "UNCONTROLLED HEADINGS" If CS.IsOnline = False then CS.Logon "","","" Do While CS.GetListItem (Looper) = TRUE 'Deactivate the preceding line and activate this next line if you're dealing with really large files that you want to break into chunks; otherwise process the entire file with the active line. 'Do While Looper<1001 and CS.GetListItem (Looper) = TRUE CS.GetListItem Looper FieldsToReport$ = "" ' CS.ControlHeadingsAll Call ReportUncontrolledHeadings(FieldsToReport$) CS.CloseRecord TRUE FieldsToReport$ = str(Looper) & Chr(34) & chr(9) & FieldsToReport$ Write #1, FieldsToReport Looper=Looper+1 Recordcounter=Recordcounter+1 Loop Recordcounter = Recordcounter-1 MsgBox "Macro completed. " & Recordcounter & " records processed." EndMacro: End Sub '********************************************** Sub ReportUncontrolledHeadings(FieldsToReport$) Dim i%,counter%,FieldContents245$,sTitle$,FieldContents$,ProcessedContents856$,NumberAndLinks$,OCLCno$,CursorRowLocation% CS.GetField "245",1,FieldContents245 sTitle$ = Right(FieldContents245,Len(FieldContents245)-5) CS.CopyControlNumber OCLCno$ = Clipboard.GetText Dim FieldsToSearchFor(18) as string FieldsToSearchFor(0) = "100" FieldsToSearchFor(1) = "110" FieldsToSearchFor(2) = "111" FieldsToSearchFor(3) = "130" FieldsToSearchFor(4) = "600" FieldsToSearchFor(5) = "610" FieldsToSearchFor(6) = "611" FieldsToSearchFor(7) = "630" FieldsToSearchFor(8) = "650" FieldsToSearchFor(9) = "651" FieldsToSearchFor(10) = "655" FieldsToSearchFor(11) = "700" FieldsToSearchFor(12) = "710" FieldsToSearchFor(13) = "711" FieldsToSearchFor(14) = "730" FieldsToSearchFor(15) = "800" FieldsToSearchFor(16) = "810" FieldsToSearchFor(17) = "811" FieldsToSearchFor(18) = "830" For i = 0 to 18 Counter = 1 Do while CS.GetField(FieldsToSearchFor(i),Counter,FieldContents$) CS.FindText Mid(FieldContents,6,Len(FieldContents)),FALSE CursorRowLocation = CS.CursorRow If CS.IsHeadingControlled(CursorRowLocation) = FALSE and ((Mid(FieldContents,5,1) <> "4" and Mid(FieldContents,5,1) <> "7") or (Mid(FieldContents,1,1) = "6" and InStr(FieldContents,"lcgft") <> 0)) then If FieldsToReport$ = "" then FieldsToReport$ = FieldContents Else FieldsToReport$ = FieldsToReport$ & " | " & FieldContents End If End If Counter = Counter + 1 Loop Next i If FieldsToReport = "" then FieldsToReport = "All headings controlled" FieldsToReport = Chr(34) & OCLCno & Chr(34) & Chr(9) & Chr(34) & sTitle & Chr(34) & chr(9) & Chr(34) & FieldsToReport End Sub