我有一個VBA模板項目,當Word文檔打開時自動運行。但是,如果我打開多個文檔,它們都共享變量值。如何聲明這些變量只與活動窗口或活動文檔相關聯?如何防止在Word文檔中共享VBA變量?
我試着在類模塊中聲明它們,但是沒有幫助。在打開的文檔之間切換我可以看到這些變量是共享的。
任何輸入讚賞...
這是我在我的模塊:
Option Private Module
Dim CurrentCommand As String
Public Function SetCurrentCommand(command)
CurrentCommand = command
End Function
Public Function GetCurrentCommand()
GetCurrentCommand = CurrentCommand
End Function
更多信息:代碼/宏開始在AutoExec的是這樣的:
Public Sub Main()
Set oAppClass.oApp = Word.Application
If PollingRate <> "" Then Application.OnTime Now + TimeValue(PollingRate), "CaptureUserViewState"
End Sub
而CaptureUserViewState是一個Sub,它駐留在一個不同的模塊中,並執行所有的檢查(比較新值和最後記錄的),他重新此子如何做的檢查:
If WL_GetterAndSetter.GetLastPageVerticalPercentage <> pageVerticalPercentScrolled Then
'Update the last value variable
WL_GetterAndSetter.SetLastPageVerticalPercentage (pageVerticalPercentScrolled)
'log change
End If
請向我們展示如何在首位聲明這些變量。 –