Dynamo Nath
Board Regular
- Joined
- Aug 5, 2009
- Messages
- 142
I'm attempting to write some code that creates a toolbar with some buttons on it that carries out some simple instructions; this is just a test before I try and incorporate it into the real spreadsheet.
The first sub creates the toolbar and its commandbarbuttons and their properties. The second sub checks which sheet is active and whether or not the macros attached to the commandbarbuttons can be run or not. If it can be run it calls the code below.
Everything works fine until an error occurs, either deliberately by stopping the code or via an error. I get error 91 - Object variable not set. I think this is caused by the variables being reset/not initialised once the error has been cleared. The button on the spreadsheet used to start the first macro running doesn't initialise the variables; the only way I can do it is by manually running the first macro from within the code editor.
Is it possible to re-initialise the variables via code?
The .State is the where the error occurs.
Thanks in advance.
The first sub creates the toolbar and its commandbarbuttons and their properties. The second sub checks which sheet is active and whether or not the macros attached to the commandbarbuttons can be run or not. If it can be run it calls the code below.
Everything works fine until an error occurs, either deliberately by stopping the code or via an error. I get error 91 - Object variable not set. I think this is caused by the variables being reset/not initialised once the error has been cleared. The button on the spreadsheet used to start the first macro running doesn't initialise the variables; the only way I can do it is by manually running the first macro from within the code editor.
Is it possible to re-initialise the variables via code?
The .State is the where the error occurs.
Thanks in advance.
Code:
Public Sub button_command()
'* Uses the tag property of the commandbar button for the Select Case
'* to execute the relevant code
Select Case Application.CommandBars.ActionControl.Tag
Case "button1"
With mycbb
Select Case .State
Case "0"
MsgBox "hello"
.State = -1 'msoButtonDown
Case "-1"
MsgBox "wibble"
.State = 0 'msoButtonUp
End Select
End With
Case "button2"
Call button_msg
End Select
End Sub