Command button to toggle worksheet event code on / off?
I wondered about that and almost mentioned same warning. But oddly (or maybe
I got in a hurry and did a boo-boo) when I used a command button from the
Control Toolbox (not the Forms tools) it actually appeared to respond to
multiple clicks. I didn't delve into it any further than that to see the
status of any other event handlers during those times. Perhaps later this
evening - running down a Hotfix for 2007 now.
"Gord Dibben" wrote:
Fred
Be very careful with that toggle on/off code I posted.
Could leave you with events disabled when you don't want them disabled if you
forget to turn back on.
I was hoping someone would help us with a method to just disable for that
worksheet.
Gord
On Sat, 28 Jul 2007 22:44:33 +0100, "Fred"
wrote:
Excel 2000.
This my first attempt to use a Command button (from the Control Toolbox) and
neither Help nor Google have provided an obvious solution to my problem.
In a recent reply to another question, Gord Dibben suggested using a
worksheet event code to change the font colour in order to highlight data
entered when editing a worksheet. Gord then suggested that one way of
toggling this event code on or off could be to use a Command button.
The codes work perfectly but I cannot locate my new Command button
statically on the toolbar but only on the worksheet where it scrolls with
the sheet.
I cannot use a Custom button that will locate on the toolbar because they
are associated with macros and my coding knowledge is negligible.
Possible solutions might be:
i) Extend Gord's main code to include a "hotkey" type toggle switch.
ii) Some code to place a suitable button on a toolbar.
Gord's code:
CommandButton1
Private Sub CommandButton1_Click()
Application.EnableEvents = False = Not _
Application.EnableEvents = False
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo ws_exit:
Application.EnableEvents = False
With Target
If .Value < "" Then
.Font.ColorIndex = 3
End If
End With
ws_exit:
Application.EnableEvents = True
End Sub
Any help or links would be greatly appreciated.
|