Forum Discussion
Declaring a variable public in VBA
- Oct 10, 2020
To declare a public variable, do so in a standard module (the kind that you create by selecting Insert > Module) instead of in the ThisWorkbook module. You only need to do this in one module.
Make sure that you use the keyword Public:
Public variablename
You can still initialize it in Workbook_Open in the ThisWorkbook module.
(You can, in fact, declare it in ThisWorkbook, but then you must refer to it as ThisWorkbook.variablename instead of just variablename)
To declare a public variable, do so in a standard module (the kind that you create by selecting Insert > Module) instead of in the ThisWorkbook module. You only need to do this in one module.
Make sure that you use the keyword Public:
Public variablename
You can still initialize it in Workbook_Open in the ThisWorkbook module.
(You can, in fact, declare it in ThisWorkbook, but then you must refer to it as ThisWorkbook.variablename instead of just variablename)
- perkin_warbeckOct 10, 2020Brass Contributor
HansVogelaar Thank you. Your solution worked perfectly.