View Single Post
 
Old 11-22-2020, 11:20 PM
Charles Kenyon Charles Kenyon is online now Windows 10 Office 2019
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,140
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