Declaring a variable as a global constant question

AxMan

New Member
Joined
Apr 16, 2015
Messages
19
Hi All,

I've declared the below variable as follows:-

Global Const FilePathName As String = "X:\Sales\Tools\Available Distribution Tool\Company"

I've tried to replace multiple file paths with the above along with the rest of the file path, but when you step through the code it doesn't seem to like it.

This is an example of an instance where I've tried to replace FilePathName:-

ActiveWorkbook.SaveAs Filename:= _ "X:\Sales\Tools\Available Distribution Tool\Company\Stock Reports\" & "Stock By Owner ID" & ".xlsx", FileFormat:=51, _
CreateBackup:=False

to

ActiveWorkbook.SaveAs Filename:= _ FilePathName & "\Stock Reports\" & "Stock By Owner ID" & ".xlsx", FileFormat:=51, _
CreateBackup:=False


Have I declared the variable correctly so it will be recognised across all sub routines?

Any help would be appreciated!
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
If you are trying to use it in other Modules, you need to use the word "Public" instead of "Global", and you should declare it outside of any procedure/function (usually at the top before any procedures/functions).
 
Upvote 0
"doesn't seem to like it"

What does that mean?
 
Upvote 0
Thanks Joe, I'm trying to use it in just one module, I have several subroutines within that module that I'm trying to use that variable in.

"Doesn't seem to like it" means I've stepped through the code and get an error:-

Compile Error:

Syntax Error
 
Upvote 0
Note that the underscore is an "end of line continuation" mark to use, so it should only ever appear at the end of a line.

So does this work?
Code:
[COLOR=#333333]ActiveWorkbook.SaveAs Filename:= FilePathName & "\Stock Reports\Stock By Owner ID.xlsx", FileFormat:=51, _[/COLOR]
[COLOR=#333333]CreateBackup:=False[/COLOR]
If not, can you confirm for us exactly which line is returning the syntax error?
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,853
Members
452,361
Latest member
d3ad3y3

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top