Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #7  
Old 11-22-2020, 11:20 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,590
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 Guessed View Post
As a public variable, its value will persist but you do need to run the macro to give it a value first. So you should rename the setProjectPath macro to Document_Open or Document_New as these will autorun with either opening an existing document or creating a new document respectively.

Alternatively, you could declare it as a constant.
My experience, tonight, disagrees. Perhaps I am just tired. I tried setting the value of a public variable declared outside a procedure and it blanked when I ran the second procedure trying to access that value.

Code:
Option Explicit 

Public projectPath As String 

Sub setFilePath() 
  Let projectPath = "This is my filepath" 
End Sub 

Sub ShowprojectPath() 
  MsgBox "projectPath = " & projectPath 
End Sub
Andrew, I admit that I am out of my comfort zone here. I initially thought the same. You have more experience with this than I do.
Reply With Quote
 



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 02:15 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