Skip to content

Instantly share code, notes, and snippets.

@jbeard4
Created February 9, 2013 23:42
Show Gist options
  • Save jbeard4/4747615 to your computer and use it in GitHub Desktop.
Save jbeard4/4747615 to your computer and use it in GitHub Desktop.
Zotero.dot
Option Explicit
Private Const CP_UTF8 = 65001
Private Const WM_COPYDATA = &H4A
#If VBA7 Then
Type COPYDATASTRUCT
dwData As LongPtr
cbData As Long
lpData As LongPtr
End Type
Private Declare PtrSafe Function FindWindow Lib "user32" Alias _
"FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName _
As String) As LongPtr
Private Declare PtrSafe Function SendMessage Lib "user32" Alias _
"SendMessageA" (ByVal hwnd As LongPtr, ByVal wMsg As Long, ByVal _
wParam As Long, lParam As Any) As Integer
Private Declare PtrSafe Function SetForegroundWindow Lib "user32" _
(ByVal hwnd As LongPtr) As Boolean
Private Declare PtrSafe Function WideCharToMultiByte Lib "Kernel32" (ByVal CodePage As Long, _
ByVal dwflags As Long, ByVal lpWideCharStr As LongPtr, _
ByVal cchWideChar As Long, lpMultiByteStr As Any, _
ByVal cchMultiByte As Long, ByVal lpDefaultChar As Long, _
ByVal lpUsedDefaultChar As Long) As Long
#Else
Type COPYDATASTRUCT
dwData As Long
cbData As Long
lpData As Long
End Type
Private Declare Function FindWindow Lib "user32" Alias _
"FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName _
As String) As Long
Private Declare Function SendMessage Lib "user32" Alias _
"SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal _
wParam As Long, lParam As Any) As Integer
Private Declare Function SetForegroundWindow Lib "user32" _
(ByVal hwnd As Long) As Boolean
Private Declare Sub CopyMemory Lib "Kernel32" Alias "RtlMoveMemory" _
(hpvDest As Any, hpvSource As Any, ByVal cbCopy As Long)
Private Declare Function WideCharToMultiByte Lib "Kernel32" (ByVal CodePage As Long, _
ByVal dwflags As Long, ByVal lpWideCharStr As Long, _
ByVal cchWideChar As Long, lpMultiByteStr As Any, _
ByVal cchMultiByte As Long, ByVal lpDefaultChar As Long, _
ByVal lpUsedDefaultChar As Long) As Long
#End If
Sub ZoteroInsertCitation()
Call ZoteroCommand("addCitation", True)
End Sub
Sub ZoteroInsertBibliography()
Call ZoteroCommand("addBibliography", False)
End Sub
Sub ZoteroEditCitation()
Call ZoteroCommand("editCitation", True)
End Sub
Sub ZoteroEditBibliography()
Call ZoteroCommand("editBibliography", True)
End Sub
Sub ZoteroSetDocPrefs()
Call ZoteroCommand("setDocPrefs", True)
End Sub
Sub ZoteroRefresh()
Call ZoteroCommand("refresh", False)
End Sub
Sub ZoteroRemoveCodes()
Call ZoteroCommand("removeCodes", False)
End Sub
Sub ZoteroCommand(cmd As String, bringToFront As Boolean)
Dim cds As COPYDATASTRUCT
#If VBA7 Then
Dim ThWnd As LongPtr
#Else
Dim ThWnd As Long
#End If
Dim a$, args$, name$
Dim i As Long
Dim ignore As Long
Dim sBuffer$
Dim lLength As Long
Dim buf() As Byte
' Get path to active document - removed since passing -zoteroIntegrationDocument doesn't work in Wine
' If ActiveDocument.Path <> "" Then
' name$ = ActiveDocument.Path & Application.PathSeparator & ActiveDocument.name
' Else
' name$ = ActiveDocument.name
' End If
' Set up command line arguments
name$ = Replace(name$, """", """""")
' args$ = "-silent -ZoteroIntegrationAgent WinWord -ZoteroIntegrationCommand " & cmd & " -ZoteroIntegrationDocument """ & name$ & """"
args$ = "-silent -ZoteroIntegrationAgent WinWord -ZoteroIntegrationCommand " & cmd
' Since VB's FindWindow call doesn't work under wine,
' just run firefox.exe directly with the relevant command
Call Shell("""C:\Program Files\Zotero Standalone\zotero.exe"" " & args$, vbNormalFocus)
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment