Public Const doesn't seem to work

Airfix9

Well-known Member
Joined
Sep 23, 2005
Messages
886
I have some code in a file called "Z-BUTTONS FY06 (New).xls":

On a module called "Constant_DB"

Code:
Public Const cstZB As String = "Z-BUTTONS FY06 (New).xls"

On a module called "ARF_New"

Code:
Workbooks(cstZB).Activate
    ActiveWindow.Visible = False

When I try to run the code, I get a Runtime Error 9 - Subscript out of range and I'm tearing my hair out trying to work out why!

The reason that I added these constants to a separate module is that many procedures in the file will refer to them and I want to be able to change them quickly and easily.

Hope that's clear enough - any help gratefully received. Of course, it is entirely probable that this is a simple issue and I can't see the wood for the trees. The file compiles fine, however and the Immediate window returns the correct value for cstZB when asked.........
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
The first thing to do is check the name is correct, including any errant spaces.
 
Upvote 0
AAAAAAAAAAAAAAAAAAAAARGH!!!!!

Told you it was simple.

** Beats head against desk and vows to stop drinking! **

Thanks, mate... :oops:
 
Upvote 0

Forum statistics

Threads
1,215,534
Messages
6,125,372
Members
449,221
Latest member
chriscavsib

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