'MacroName:SearchHeading 'MacroDescription:Search WorldCat for the current heading 'Macro written by: Joel Hahn, Niles Public Library District 'Macro last modified: 14 November 2006 Declare Function NormalizeSearch(sInput As String) As String Declare Function RemoveDelimiters(sInput As String) As String Declare Function RemovePunctuation(sInput As String) as String Declare Function RemoveSubfield(sFieldData As String, sSubfield As String) As String Sub Main Dim CS As Object Set CS = CreateObject("Connex.Client") bool = CS.GetFieldLine(CS.CursorRow, sField) If UCase(sField) = UCase("Data contains non-latin script") Then MsgBox "This macro only works with Latin-alphabet fields. Exiting..." Exit Sub End If nTag = Val(Left(sField, 3)) Select Case nTag Case 100,700,110,710,130,440,490,630,730,830,150,650,151,651,655 bool = CS.IsOnline If bool = FALSE Then bool = CS.Logon("","","") If bool = FALSE Then MsgBox "Unable to log on. Exiting..." Exit Sub End If End If sSearchTerm = NormalizeSearch(sField) If sSearchTerm <> "" Then If CS.ItemType = 0 Then 'If currently viewing an online WorldCat bib record, pin it before searching CS.SendKeys "", -1 CS.SendKeys "%vp", -1 End If nHits = CS.Search("WC", sSearchTerm) End If Case Else MsgBox "The cursor is not in a searchable heading. Exiting..." Exit Sub End Select End Sub Function NormalizeSearch(sInput As String) as String nTag = Val(Left(sInput, 3)) Select Case nTag Case 100 sInput = RemoveSubfield(sInput, "e") sInput = RemoveSubfield(sInput, "f") sInput = RemoveSubfield(sInput, "g") sInput = RemoveSubfield(sInput, "k") sInput = RemoveSubfield(sInput, "l") sInput = RemoveSubfield(sInput, "n") sInput = RemoveSubfield(sInput, "p") sInput = RemoveSubfield(sInput, "s") sInput = RemoveSubfield(sInput, "t") sInput = RemoveSubfield(sInput, "4") sTempSearch = RemoveDelimiters(sInput) sTempSearch = RemovePunctuation(sTempSearch) NormalizeSearch = "au:" & Mid(sTempSearch, 6) Case 110,111 sInput = RemoveSubfield(sInput, "f") sInput = RemoveSubfield(sInput, "g") sInput = RemoveSubfield(sInput, "h") sInput = RemoveSubfield(sInput, "k") sInput = RemoveSubfield(sInput, "l") sInput = RemoveSubfield(sInput, "p") sInput = RemoveSubfield(sInput, "s") sInput = RemoveSubfield(sInput, "t") sInput = RemoveSubfield(sInput, "4") sTempSearch = RemoveDelimiters(sInput) sTempSearch = RemovePunctuation(sTempSearch) NormalizeSearch = "cn:" & Mid(sTempSearch, 6) Case 130,730 sInput = RemoveSubfield(sInput, "h") sInput = RemoveSubfield(sInput, "l") sInput = RemoveSubfield(sInput, "x") sInput = RemoveSubfield(sInput, "3") sInput = RemoveSubfield(sInput, "5") sTempSearch = RemoveDelimiters(sInput) sTempSearch = RemovePunctuation(sTempSearch) NormalizeSearch = "ti:" & Mid(sTempSearch, 6) Case 440,490 sInput = RemoveSubfield(sInput, "l") sInput = RemoveSubfield(sInput, "v") sTempSearch = RemoveDelimiters(sInput) sTempSearch = RemovePunctuation(sTempSearch) NormalizeSearch = "se:" & Mid(sTempSearch, 6) Case 600,610,611,630 If nTag <> 611 Then sInput = RemoveSubfield(sInput, "e") sInput = RemoveSubfield(sInput, "f") sInput = RemoveSubfield(sInput, "h") sInput = RemoveSubfield(sInput, "l") sInput = RemoveSubfield(sInput, "u") sInput = RemoveSubfield(sInput, "2") sInput = RemoveSubfield(sInput, "3") sInput = RemoveSubfield(sInput, "4") sTempSearch = RemoveDelimiters(sInput) sTempSearch = RemovePunctuation(sTempSearch) NormalizeSearch = "su:" & Mid(sTempSearch, 6) Case 650,651,655 sInput = RemoveSubfield(sInput, "c") sInput = RemoveSubfield(sInput, "d") sInput = RemoveSubfield(sInput, "e") sInput = RemoveSubfield(sInput, "2") sInput = RemoveSubfield(sInput, "3") sInput = RemoveSubfield(sInput, "5") sTempSearch = RemoveDelimiters(sInput) sTempSearch = RemovePunctuation(sTempSearch) NormalizeSearch = "su:" & Mid(sTempSearch, 6) Case 700 sTitleInput = sInput sInput = RemoveSubfield(sInput, "e") sInput = RemoveSubfield(sInput, "f") sInput = RemoveSubfield(sInput, "g") sInput = RemoveSubfield(sInput, "h") sInput = RemoveSubfield(sInput, "k") sInput = RemoveSubfield(sInput, "l") sInput = RemoveSubfield(sInput, "m") sInput = RemoveSubfield(sInput, "n") sInput = RemoveSubfield(sInput, "o") sInput = RemoveSubfield(sInput, "p") sInput = RemoveSubfield(sInput, "r") sInput = RemoveSubfield(sInput, "s") sInput = RemoveSubfield(sInput, "t") sInput = RemoveSubfield(sInput, "x") sInput = RemoveSubfield(sInput, "3") sInput = RemoveSubfield(sInput, "4") sInput = RemoveSubfield(sInput, "5") sTempAuthSearch = RemoveDelimiters(sInput) sTempAuthSearch = RemovePunctuation(sTempAuthSearch) sInput = RemoveSubfield(sTitleInput, "a") sInput = RemoveSubfield(sTitleInput, "b") sInput = RemoveSubfield(sTitleInput, "c") sInput = RemoveSubfield(sTitleInput, "d") sInput = RemoveSubfield(sTitleInput, "e") sInput = RemoveSubfield(sTitleInput, "f") sInput = RemoveSubfield(sTitleInput, "h") sInput = RemoveSubfield(sTitleInput, "j") sInput = RemoveSubfield(sTitleInput, "l") sInput = RemoveSubfield(sTitleInput, "q") sInput = RemoveSubfield(sTitleInput, "u") sInput = RemoveSubfield(sTitleInput, "x") sInput = RemoveSubfield(sTitleInput, "3") sInput = RemoveSubfield(sTitleInput, "4") sInput = RemoveSubfield(sTitleInput, "5") sTempTitleSearch = RemoveDelimiters(sInput) sTempTitleSearch = RemovePunctuation(sTempTitleSearch) sTempSearch = "au:" & Mid(sTempAuthSearch, 6) If Mid(sTempTitleSearch, 6) <> "" Then sTempSearch = sTempSearch & " and ti:" & Mid(sTempTitleSearch, 6) End If NormalizeSearch = sTempSearch Case 710 sTitleInput = sInput sInput = RemoveSubfield(sInput, "f") sInput = RemoveSubfield(sInput, "g") sInput = RemoveSubfield(sInput, "h") sInput = RemoveSubfield(sInput, "k") sInput = RemoveSubfield(sInput, "l") sInput = RemoveSubfield(sInput, "m") 'sInput = RemoveSubfield(sInput, "n") sInput = RemoveSubfield(sInput, "o") sInput = RemoveSubfield(sInput, "p") sInput = RemoveSubfield(sInput, "r") sInput = RemoveSubfield(sInput, "s") sInput = RemoveSubfield(sInput, "t") sInput = RemoveSubfield(sInput, "u") sInput = RemoveSubfield(sInput, "x") sInput = RemoveSubfield(sInput, "3") sInput = RemoveSubfield(sInput, "4") sInput = RemoveSubfield(sInput, "5") sTempAuthSearch = RemoveDelimiters(sInput) sTempAuthSearch = RemovePunctuation(sTempAuthSearch) sInput = RemoveSubfield(sTitleInput, "a") sInput = RemoveSubfield(sTitleInput, "b") sInput = RemoveSubfield(sTitleInput, "c") sInput = RemoveSubfield(sTitleInput, "e") sInput = RemoveSubfield(sTitleInput, "f") sInput = RemoveSubfield(sTitleInput, "h") sInput = RemoveSubfield(sTitleInput, "l") sInput = RemoveSubfield(sTitleInput, "u") sInput = RemoveSubfield(sTitleInput, "x") sInput = RemoveSubfield(sTitleInput, "3") sInput = RemoveSubfield(sTitleInput, "4") sInput = RemoveSubfield(sTitleInput, "5") sTempTitleSearch = RemoveDelimiters(sInput) sTempTitleSearch = RemovePunctuation(sTempTitleSearch) sTempSearch = "cn:" & Mid(sTempAuthSearch, 6) If Mid(sTempTitleSearch, 6) <> "" Then sTempSearch = sTempSearch & " and ti:" & Mid(sTempTitleSearch, 6) End If NormalizeSearch = sTempSearch Case 711 sTitleInput = sInput sInput = RemoveSubfield(sInput, "f") sInput = RemoveSubfield(sInput, "g") sInput = RemoveSubfield(sInput, "h") sInput = RemoveSubfield(sInput, "k") sInput = RemoveSubfield(sInput, "l") 'sInput = RemoveSubfield(sInput, "n") sInput = RemoveSubfield(sInput, "p") sInput = RemoveSubfield(sInput, "s") sInput = RemoveSubfield(sInput, "t") sInput = RemoveSubfield(sInput, "u") sInput = RemoveSubfield(sInput, "x") sInput = RemoveSubfield(sInput, "3") sInput = RemoveSubfield(sInput, "4") sInput = RemoveSubfield(sInput, "5") sTempAuthSearch = RemoveDelimiters(sInput) sTempAuthSearch = RemovePunctuation(sTempAuthSearch) sInput = RemoveSubfield(sTitleInput, "a") sInput = RemoveSubfield(sTitleInput, "c") sInput = RemoveSubfield(sTitleInput, "d") sInput = RemoveSubfield(sTitleInput, "e") sInput = RemoveSubfield(sTitleInput, "f") sInput = RemoveSubfield(sTitleInput, "h") sInput = RemoveSubfield(sTitleInput, "l") sInput = RemoveSubfield(sTitleInput, "q") sInput = RemoveSubfield(sTitleInput, "u") sInput = RemoveSubfield(sTitleInput, "x") sInput = RemoveSubfield(sTitleInput, "3") sInput = RemoveSubfield(sTitleInput, "4") sInput = RemoveSubfield(sTitleInput, "5") sTempTitleSearch = RemoveDelimiters(sInput) sTempTitleSearch = RemovePunctuation(sTempTitleSearch) sTempSearch = "cn:" & Mid(sTempAuthSearch, 6) If Mid(sTempTitleSearch, 6) <> "" Then sTempSearch = sTempSearch & " and ti:" & Mid(sTempTitleSearch, 6) End If NormalizeSearch = sTempSearch Case 800 sInput = RemoveSubfield(sInput, "f") sInput = RemoveSubfield(sInput, "h") sInput = RemoveSubfield(sInput, "j") sInput = RemoveSubfield(sInput, "l") sInput = RemoveSubfield(sInput, "u") sInput = RemoveSubfield(sInput, "v") sInput = RemoveSubfield(sInput, "4") sTempSearch = RemoveDelimiters(sInput) sTempSearch = RemovePunctuation(sTempSearch) NormalizeSearch = "se:" & Mid(sTempSearch, 6) Case 810,811 sInput = RemoveSubfield(sInput, "f") sInput = RemoveSubfield(sInput, "h") sInput = RemoveSubfield(sInput, "l") sInput = RemoveSubfield(sInput, "q") sInput = RemoveSubfield(sInput, "u") sInput = RemoveSubfield(sInput, "v") sInput = RemoveSubfield(sInput, "4") sTempSearch = RemoveDelimiters(sInput) sTempSearch = RemovePunctuation(sTempSearch) NormalizeSearch = "se:" & Mid(sTempSearch, 6) Case 830 sInput = RemoveSubfield(sInput, "h") sInput = RemoveSubfield(sInput, "l") sInput = RemoveSubfield(sInput, "v") sTempSearch = RemoveDelimiters(sInput) sTempSearch = RemovePunctuation(sTempSearch) NormalizeSearch = "se:" & Mid(sTempSearch, 6) Case Else NormalizeSearch = "" Exit Function End Select End Function Function RemoveSubfield(sFieldData As String, sSubfield As String) sTempData = Mid(sFieldData, 6) sTempTagInds = Left(sFieldData, 5) place = InStr(sTempData, Chr(223) & sSubfield) If place > 1 Then place2 = InStr(place + 1, sTempData, Chr(223)) If place2 = 0 Then sTempData = sTempTagInds & RTrim(Left(sTempData, place - 1)) Else sTempData = sTempTagInds & RTrim(Left(sTempData, place - 1)) & " " & LTrim(Mid(sTempData, place2)) End If sFieldData = sTempData ElseIf place = 1 Then place2 = InStr(place + 1, sTempData, Chr(223)) If place2 = 0 Then sTempData = sTempTagInds & RTrim(Left(sTempData, place - 1)) Else sTempData = sTempTagInds & RTrim(Left(sTempData, place - 1)) & " " & LTrim(Mid(sTempData, place2)) End If sFieldData = sTempData End If If sSubfield = "a" and Mid(sFieldData, 6, 1) <> Chr(223) Then place = InStr(sTempData, Chr(223)) If place > 0 Then sTempData = sTempTagInds & " " & LTrim(Mid(sTempData, place)) Else sTempData = sTempTagInds End If sFieldData = sTempData End If RemoveSubfield = sFieldData End Function Function RemoveDelimiters(sInput As String) As String sTempData = sInput Do While InStr(sTempData, Chr(223)) place = InStr(sTempData, Chr(223)) sTempData = RTrim(Left(sTempData, place - 1)) & " " & LTrim(Mid(sTempData, place + 2)) Loop RemoveDelimiters = sTempData End Function Function RemovePunctuation(sInput As String) as String sTempData = sInput i = 1 Do While i <= Len(sTempData) sChar = Mid(sTempData, i, 1) Select Case sChar Case "(", ")", ";", ",", Chr(34), "'", "/", "=", ":", "[", "]", "{", "}", "\", "&", "|" If i > 1 Then sTempData = Left(sTempData, i-1) & Mid(sTempData, i+1) Else sTempData = Mid(sTempData, i+1) End If i = i - 1 Case "-" If i > 1 Then sTempData = Left(sTempData, i-1) & " " & Mid(sTempData, i+1) Else sTempData = Mid(sTempData, i+1) End If End Select i = i + 1 Loop RemovePunctuation = sTempData End Function