#1
|
|||
|
|||
Declaring a Constant
I understand how to declare a Public Constant and set its value eg . . .
Public Const <name> as String = <value> However I want to define the value as a concatenated string eg . . . Public Const <name> as String = "C:\Users" & Environ$("username") & "\OneDrive" . . . but this fails with "Compile error". I can get round this by just declaring the constant's name, then setting its value in the Auto-Open macro. I was wondering if there is a better or neater way to do this ? |
#2
|
||||
|
||||
A constant cannot be the result of a function since that result could change. Similarly you can't declare a constant and then set its value in another routine.
You can either use a variable - which I assume is what you meant with your second option - or use a function that returns the value you want. You can then simply use that function name as you would the constant. |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Declare Constant for Chr(14) | VBorNotVB | Word VBA | 3 | 12-06-2020 09:28 PM |
Declaring Public variables and accessing in other modules | rekent | Word VBA | 16 | 11-24-2020 02:09 PM |
Declaring a variable that is known across modules | Officer_Bierschnitt | Excel Programming | 5 | 11-18-2015 12:28 PM |
Keep cell in formula constant | jprt68 | Excel | 1 | 06-26-2012 08:31 AM |
Keeping the top row constant in Excel | MSmand | Excel | 2 | 07-13-2011 01:14 PM |