Windows 8机器(有效): Microsoft Office专业增强版2013 Windows 10计算机(不起作用): Microsoft Office 365
模板(.dotm文件)被放置在Word的“启动”文件夹中。 启动Word时,出现空白屏幕。单击“文件”使Word立即退出,没有错误消息。 外接程序具有一个名为MainModule的模块和一个名为WordApp的类。 AutoExec会触发一个调用伪函数的循环。
MainModule:
'event processor class instance
Dim myWordApp As WordApp
Sub Register_Event_Handler()
Set myWordApp.appWord = Word.Application
End Sub
'gets executed automatically
Sub AutoExec()
Set myWordApp = New WordApp
Call MainProgram
End Sub
Sub MainProgram()
Register_Event_Handler
Do While True
testFunction
DoEvents
Loop
End Sub
'dummy function gets called in loop
Private Sub testFunction()
Dim i As Integer
i = 0
i = i + 1
End Sub
WordApp类:
Public WithEvents appWord As Word.Application
'fires upon closing word
Private Sub appWord_DocumentBeforeClose(ByVal Doc As Document, Cancel As
Boolean)
MsgBox "Closing"
End Sub