According to J. Walkenbach:
That's exactly what happens when I check the value of any public and static variables in the Watch window.
In my add-in, I've initialised a couple of checks and log writing (e.g. OS version, Excel version, library associations, availability of add-in files, VBE version, etc.) when Excel opens and before the user actually starts working with the add-in (button clicking, userforms, etc.). The idea is not to bother users with error messages, if smth is missing or they intend to use Excel for other needs. Instead I'd like to have the results of initial checks reserved in public variables (?) so that the user is warned and necessary error handling is carried out only when the user actually starts working with my add-in (e.g. running another subroutine such as a userform after initialisation is complete).
How can I achieve this without storing public variable values in Excel sheet or a separate file? Is it somehow possible given the limitations of Excel VBA?
Thanks!
...if the procedure is halted by an End statement, static variables do lose their values.
That's exactly what happens when I check the value of any public and static variables in the Watch window.
Code:
[COLOR=darkblue]Public[/COLOR] slxRibbon [COLOR=darkblue]As[/COLOR] IRibbonUI[COLOR=darkblue]Public[/COLOR] [COLOR=darkblue]Declare[/COLOR] [COLOR=darkblue]Function[/COLOR] InternetGetConnectedStateEx [COLOR=darkblue]Lib[/COLOR] "wininet.dll" ([COLOR=darkblue]ByRef[/COLOR] lpdwFlags [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]Long[/COLOR], [COLOR=darkblue]ByVal[/COLOR] lpszConnectionName [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]String[/COLOR], [COLOR=darkblue]ByVal[/COLOR] dwNameLen [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]Integer[/COLOR], [COLOR=darkblue]ByVal[/COLOR] dwReserved [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]Long[/COLOR]) [COLOR=darkblue]As[/COLOR] Long
[COLOR=darkblue]Public[/COLOR] [COLOR=darkblue]Const[/COLOR] sLogFile [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]String[/COLOR] = "mylogfile.log"
[COLOR=darkblue]Public[/COLOR] [COLOR=darkblue]Const[/COLOR] sSettingsFolder [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]String[/COLOR] = ".settingsfolder"
[COLOR=darkblue]Public[/COLOR] [COLOR=darkblue]Const[/COLOR] sSettingsFile [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]String[/COLOR] = "settings.cfg"
[COLOR=darkblue]Public[/COLOR] [COLOR=darkblue]Const[/COLOR] slxVersion [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]String[/COLOR] = "v3.0 Build 011118"
[COLOR=darkblue]Public[/COLOR] bReadOnly [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]Boolean[/COLOR]
[COLOR=darkblue]Public[/COLOR] sOSVersion [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]String[/COLOR]
[COLOR=darkblue]Public[/COLOR] dXLVersion [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]Double[/COLOR]
[COLOR=darkblue]Public[/COLOR] dVBEVersion [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]Double[/COLOR]
[COLOR=darkblue]Public[/COLOR] bInternetConnStatus [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]Boolean[/COLOR]
[COLOR=darkblue]Sub[/COLOR] AddInInitialise(Ribbon [COLOR=darkblue]As[/COLOR] IRibbonUI)
[COLOR=green]' Checking code goes here...[/COLOR]
[COLOR=darkblue]End[/COLOR] [COLOR=darkblue]Sub
[/COLOR][COLOR=darkblue]Sub[/COLOR] AnotherSubroutineInAnotherModule()
[COLOR=green]'Check/call values of public variables from another subroutine in another module[/COLOR]
[COLOR=darkblue]End[/COLOR] [COLOR=darkblue]Sub[/COLOR]
In my add-in, I've initialised a couple of checks and log writing (e.g. OS version, Excel version, library associations, availability of add-in files, VBE version, etc.) when Excel opens and before the user actually starts working with the add-in (button clicking, userforms, etc.). The idea is not to bother users with error messages, if smth is missing or they intend to use Excel for other needs. Instead I'd like to have the results of initial checks reserved in public variables (?) so that the user is warned and necessary error handling is carried out only when the user actually starts working with my add-in (e.g. running another subroutine such as a userform after initialisation is complete).
How can I achieve this without storing public variable values in Excel sheet or a separate file? Is it somehow possible given the limitations of Excel VBA?
Thanks!
Last edited: