ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   toggle button & event code (https://www.excelbanter.com/excel-programming/327452-re-toggle-button-event-code.html)

Bob Umlas[_3_]

toggle button & event code
 
Event codes often run even with events off, especially for activeX objects
(forms, for example). What I do is instead of what you have, (or in
addition), I use:
ActiveSheet.unprotect
Application.EnableEvents = False
NotNow=True 'a global boolean
ActiveSheet.btToggle.Value = False
NotNow=False
Range("title").Value = "NEW TICKET"

and in the event code for the btToggle, my first line is
If NotNow then exit sub

HTH
Bob Umlas
Excel MVP

"benb" wrote in message
...
I've got one that's really stumped me. In my code, when the user opens

the
workbook, I have it set to change the title on the worksheet to a certain
value. There is also a toggle button on the sheet that is used to change

the
title so I set the value of the button to equal the value of the title.

The
code looks something like this:

ActiveSheet.unprotect
Application.EnableEvents = False
ActiveSheet.btToggle.Value = False
Range("title").Value = "NEW TICKET"

The problem is that there is some change event code that executes when I

set
the value of the toggle button EVEN THOUGH I thought I had disabled events

in
the code associated with the open event. I've tried disabling the button,
unlocking, and still it is executing the change event code. This wouldn't

be
a problem if the change event code didn't give me an error. The code that
causes the error is:

If Target.Count 1 Then
Application.Undo
MsgBox prompt:="Please only make changes to one field at a time.",
Title:="Error!", Buttons:=vbCritical
Application.EnableEvents = True
Exit Sub
Else
'some code
End If

??????????????????????????????????





All times are GMT +1. The time now is 06:52 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com