'MacroName:SirsiPasteUnicode 'MacroDescription:Paste a Symphony Unicode-format field from the Clipboard into Connexion 'Macro created by: Joel Hahn, Niles Public Library District 'Macro last modified: 8 February 2017 Declare Function GetActiveWindow Lib "user32" () As Long Declare Function OpenClipboard Lib "user32" Alias "OpenClipboard" (ByVal hwnd As Long) As Long Declare Function GetClipboardData Lib "user32" Alias "GetClipboardData" (ByVal wFormat As Long) As Long Declare Function CloseClipboard Lib "user32" Alias "CloseClipboard" () As Long Declare Function GlobalLock Lib "kernel32" Alias "GlobalLock" (ByVal hMem As Long) As Long Declare Function GlobalUnlock Lib "kernel32" Alias "GlobalUnlock" (ByVal hMem As Long) As Long Declare Function lstrlen Lib "kernel32" Alias "lstrlenW" (ByVal lpString As Long) As Long Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pTo As Any, uFrom As Any, ByVal lSize As Long) Function PointerToStringA(lpStringA As Long) As String Dim Buffer() As Integer Dim nLen As Long 'If lpStringA Then nLen = lstrlen(lpStringA) If nLen Then ReDim Buffer(0 To (nLen - 1)) As Integer CopyMemory Buffer(0), ByVal lpStringA, nLen * 2 for i = 0 to (nLen-1)' * 2 if Buffer(i) < 128 and Buffer(i) > 0 Then psa = psa & Chr(Buffer(i)) Else 'Elseif Buffer(i) > 128 Then 'psa = psa & "|" & Hex(Buffer(i)) & "|" 'Chr(Buffer(i)) psa = psa & "&#x" & Hex(Buffer(i)) & ";" 'Chr(Buffer(i)) ' psa = psa & "|" & CStr(Buffer(i)) & "|" 'Chr(Buffer(i)) End If 'If len(psa) > 80 Then psa = psa & Chr(10) Next PointerToStringA = psa 'StrConv(Buffer, vbUnicode) End If 'End If End Function Sub Main CF_DSPTEXT = &H81 CF_OEMTEXT = 7 CF_TEXT = 1 CF_UNICODETEXT = 13 Dim CS As Object On Error Resume Next Set CS = GetObject(,"Connex.Client") On Error GoTo 0 If CS Is Nothing Then Set CS = CreateObject("Connex.Client") End If clipfmt = (Clipboard.GetFormat(1) OR Clipboard.GetFormat(7)) If clipfmt = FALSE Then MsgBox "No text on the Clipboard" Else 'text$ = Clipboard.GetText(1) 'If text$ = "" Then Clipboard.GetText(7) nCurRow = CS.CursorRow nCurCol = CS.CursorColumn hwnd = GetActiveWindow() bool = OpenClipboard(hwnd) Dim hData as Long Dim lpData as Long hData = GetClipboardData(CF_UNICODETEXT) 'If hData Then lpData = GlobalLock(hData) text$ = PointerToStringA(lpData) Call GlobalUnlock(hData) ' End If bool = CloseClipboard() Do While InStr(text$, "|") place = InStr(text$, "|") lt$="" : rt$="" If place>1 Then lt$=Left(text$, place-1) rt$ = Mid(text$, place+1) text$ = lt$ & " " & Chr(223) & Left(rt$, 1) & " " & Mid(rt$, 2) Loop bool = CS.InsertText(text$) 'CS.CursorColumn = nCurCol End If Done: End Sub