View Single Post
 
Old 11-24-2020, 01:09 PM
Charles Kenyon Charles Kenyon is offline Windows 10 Office 2019
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,537
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

Quote:
Originally Posted by gmaxey View Post
The public variable needs to be a standard module. You can set it use Document_Open in the ThisDocument module or you could set it using AutoOpen in the same standard module. You don't need Static anywhere.

If I want this in a global template, what sets the variable's value? That is where I was going with Static AutoExec. Perhaps the AutoExec will do it without the Static so long as the variable is set as public in the class module.



With

Code:
Public strTest as String
in the ThisDocument Module
The following macro in a standard module in the same template generates a Variable not defined error. This is true even though the editor will correct the case of the variable name if typed in all lower case.
Code:
Sub AutoExec()
    Let strTest = "This is a test"
    MsgBox strTest
 End Sub

This also generated an error in hidden module when I attempted to load it as an Add-In.
Reply With Quote