Pookiemeister
Well-known Member
- Joined
- Jan 6, 2012
- Messages
- 626
- Office Version
- 365
- 2010
- Platform
- Windows
I am trying to get a better understanding how to declare Public variables and call them in various subs (mainly Private Subs). I am using the message box to test my code. O.K. so just below the Option Explicit and above a Private Sub, I declared a Public variable.
The above code works as expected. However the code below displays a Run-time error 424 Object Required.
Is it because I didn't do the following code before my message box.
Or should I of just created a Public Sub that displays the following inside a module and called it.
Thank You.
Code:
Option Explicit
Public mySheet As Worksheet
Private Sub cmdbtnOpen_Click()
Set mySheet = ActiveSheet
MsgBox mySheet.Name
End Sub
Code:
Private Sub cmdbtnDone_Click()
MsgBox mySheet.Name
End Sub
Code:
Set mySheet = ActiveSheet
Or should I of just created a Public Sub that displays the following inside a module and called it.
Code:
Public Sub Messagebox()
Set mySheet = ActiveSheet
MsgBox mySheet.Name
End Sub
Thank You.