nousername
03-22-2008, 08:09 PM
I am trying to run some code contain in ThisWorkBook under the sub Workbook_SheetSelectionChange. I am trying to use some code in module1 to toggle the ThisWorkbook code on and off when the user select that option under the contextmenu.
Where am I going wrong with the code below?
Module1 Code:
Public bSwitch As Boolean
Public bRw As Boolean
Sub MyTestCode()
'Enable user to switch on/off with a right click prompt
If bSwitch Then
If MsgBox("Shut off", 36) = 7 Then Exit Sub
Else
If MsgBox("Turn on", 36) = 7 Then
ThisWorkbook.Test
End If
'Toggle boolean variable on/off switch
If Selection.Rows.Count > 1 Then
bRw = False
Else
bRw = True
End If
bSwitch = Not bSwitch
End If
End Sub
ThisWorkbook Code:
Public Sub Test()
If Not bSwitch Then Exit Sub
Else
ThisWorkbook.Workbook_SheetSelectionChange
End If
End Sub
Public Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
'If we are running procedure or not:
If Not bSwitch Then Exit Sub
' More code is located here removed for posting.
End Sub
Where am I going wrong with the code below?
Module1 Code:
Public bSwitch As Boolean
Public bRw As Boolean
Sub MyTestCode()
'Enable user to switch on/off with a right click prompt
If bSwitch Then
If MsgBox("Shut off", 36) = 7 Then Exit Sub
Else
If MsgBox("Turn on", 36) = 7 Then
ThisWorkbook.Test
End If
'Toggle boolean variable on/off switch
If Selection.Rows.Count > 1 Then
bRw = False
Else
bRw = True
End If
bSwitch = Not bSwitch
End If
End Sub
ThisWorkbook Code:
Public Sub Test()
If Not bSwitch Then Exit Sub
Else
ThisWorkbook.Workbook_SheetSelectionChange
End If
End Sub
Public Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
'If we are running procedure or not:
If Not bSwitch Then Exit Sub
' More code is located here removed for posting.
End Sub