Declare Const with a string

Jayce72

Registered User.
Local time
Today, 19:03
Joined
Sep 26, 2011
Messages
60
Hi

Im trying to declare a const

I have declared

Dim strPRX as string.
strPRX = "Test"

Im using:
Const spath = "C:\Users\Jim" & strPRX & ""

I Get:
spath = C:\Users\Jim\& strPRX &\

What Im trying to achieve is that spath = C:\Users\Jim\Test\

Any help please
 
try
Code:
Const spath = "C:\Users\Jim\" & strPRX & "\"
 
have you posted what you are doing correctly? VBA doesn't create characters out of thin air

there is no way

Im using:
Const spath = "C:\Users\Jim" & strPRX & ""

will add the additional \ characters

spath = C:\Users\Jim\& strPRX &\
 
have you posted what you are doing correctly? VBA doesn't create characters out of thin air

there is no way

Im using:
Const spath = "C:\Users\Jim" & strPRX & ""

will add the additional \ characters

spath = C:\Users\Jim\& strPRX &\

Hi - thanks - I've messed around with this so much I might have written it incorrectly.

I have a path that is always: C:\Users\Jim\
I then create a new folder called Test

I am then trying to get: const spath = "string etc"

to say : C:\Users\Jim\Test\
 
by its definition, a constant is a constant - you cannot assign a variable to it. So strPRX also needs to be a constant.

Alternatively, change spath from const to dim
 
To amplify what CJ is saying, the only way to get spath to be combined from two strings is to define it originally that way as a constant, and constants must be defined in a declaration section, not in executable code.

If you change from Const to Dim, it becomes an ordinary variable for which values can be assigned dynamically.
 

Users who are viewing this thread

Back
Top Bottom