Public declaration crashes.

pdbowling

Registered User.
Local time
Today, 13:35
Joined
Feb 14, 2003
Messages
179
Hi,
This is Excel VBA.....
I've got a variable that I want to be able to access from other subs (it's in a sub) so I declared it Public. It crashes at the declaration saying:

invalid attribute in sub or function

Do I need to set an attribute or function in Excel to allow Public decs?
Thanks all
PB
 
Did you declare it public within a sub? Like

Private Sub MySub()
Public myVariable as string

Code

End Sub

?
If so, that's your problem. Declare Public variables in the declarations section of the module (i.e. at the top of all code) OUTSIDE of all of the procedures. Like

Option Explicit
Public myVariable as string

Private Sub mySub()

End Sub
 
Oh.

Well, isn't that neat. Thank you so much. I should have remembered that from object orientation, huh?
PB
 

Users who are viewing this thread

Back
Top Bottom