Global variable for add-in?

paipimenta

Board Regular
Joined
Apr 7, 2010
Messages
103
I'm working on an add-in that will have a user-form to make changes to a complex workbook. The add-in changes workbook "Audit Form.xls". How can I set this file name as a global constant in my add-in, so that I can just change this file name once in the add-in?

I'm looking for something like this....
Code:
Public Contant auditFileName As String
auditFileName = "Audit Form.xls"
 

Some videos you may like

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.

Mike Blackman

Well-known Member
Joined
Jun 8, 2007
Messages
2,494
Hi,

At the top of one of your modules house something like;

Code:
Public StrFileName as string
although I'd suggest writing the value to a name as if you have a single unhandled error within the code then and variables will be lost. If you write it to a name you can always refer to it as such;

Code:
ThisWorkbook.Range("MyFileName")
 

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
34,986
Office Version
365, 2019, 2016, 2010
Platform
Windows, MacOS
If you want a constant in your code:
Code:
Public Const auditFileName As String = "Audit Form.xls"
 

Watch MrExcel Video

Forum statistics

Threads
1,099,283
Messages
5,467,739
Members
406,549
Latest member
midcoastchris04

This Week's Hot Topics

Top