错误发生在这里:
Application.Run "Macro2.Execute", param
...
执行是从另一个模块中安装的其他模块“ Macro2 ”调用的公共子。
运行代码时:
如果没有打开的Word文档= 没有错误
如果Word文档的另一个实例打开= 发生声明错误。
这有什么问题吗? :(
整个代码如下:
Dim objWord As Object
On Error Resume Next 'suppress error checking for the next instruction
Set objWord = GetObject(, "Word.Application")
If objWord Is Nothing Then
'no instance, so make a new one
Set objWord = CreateObject("Word.Application")
bNewInstance = True
End If
On Error GoTo 0 'resume error checking
'Close Document1
ActiveDocument.Close wdDoNotSaveChanges
' Open the global template
Set docAddIn = objWord.Documents.Open("C:\WordAPI\GlobalTemplate.dotm")
docAddIn.ActiveWindow.Visible = False
' Run the the public sub Execute from global template module "Macro2"
Application.Run "Macro2.Execute", param