Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 11-24-2020, 07:39 AM
gmaxey gmaxey is offline Declaring Public variables and accessing in other modules Windows 10 Declaring Public variables and accessing in other modules Office 2016
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,636
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
Default


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.
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #2  
Old 11-24-2020, 01:09 PM
Charles Kenyon Charles Kenyon is offline Declaring Public variables and accessing in other modules Windows 10 Declaring Public variables and accessing in other modules Office 2019
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,592
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
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Declaring Public variables and accessing in other modules Combining 3 Modules into 1 Jude24Joy Word VBA 5 02-01-2017 04:20 PM
Declaring Public variables and accessing in other modules Declaring a variable that is known across modules Officer_Bierschnitt Excel Programming 5 11-18-2015 12:28 PM
Array to iterate through variables and trap blank variables Marrick13 Word VBA 5 08-04-2015 06:19 AM
can word: make variables, find appropriate pages, fill out pages with variables, print only those 20GT Word VBA 1 10-15-2014 09:48 PM
Declaring Public variables and accessing in other modules Empty Modules Greg S. Excel Programming 2 07-30-2013 01:38 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 08:08 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft