Paul,
EnableEvents doesn't apply to controls on a user form since these are
managed by VBA, not the Excel Application directly. You can create your own
EnableEvents switch as a module level Boolean variable and write code to
turn it TRUE or FALSE when needed. Then you'd code your events (such as the
Click event) to exit immediately if your own EnableEvents is TRUE. E.g.,
Option Explicit
Public MyEnableEvents As Boolean
Private Sub CommandButton1_Click()
If MyEnableEvents = False Then
Exit Sub
End If
MyEnableEvents = False
ToggleButton1.Value = Not ToggleButton1.Value
MyEnableEvents = True
End Sub
Private Sub ToggleButton1_Change()
If MyEnableEvents = False Then
Exit Sub
End If
MsgBox "Normal Code"
'''
' normal code goes here
''
End Sub
Private Sub UserForm_Initialize()
MyEnableEvents = True
End Sub
--
Cordially,
Chip Pearson
Microsoft MVP - Excel, 10 Years
Pearson Software Consulting
www.cpearson.com
(email on the web site)
"PaulW" <(E-Mail Removed)> wrote in message
news:1485609C-1B25-404A-8EDD-(E-Mail Removed)...
> I'm trying to make a userform. And one thing I want it to do is change the
> value on a togglebutton to True.
>
> But I have some code on that togglebuttons_click event which triggers when
> the value is changed (not only when it clicks?) which recalls the macro
> that
> changed the value.
>
> So what I end up with is an infinate loop, when all I wanted to do was
> change the togglebuttons value. I've tried adding in
> Application.EnableEvents
> = False, but the togglebutton_click event still triggers. Is there a way
> round that?