M
mickey
The code I'm going to refer to ultimately performs correctly, but results in
an unexpected caption display on application exit.
On CommandButton_Click two subroutines are called that alternate the
CommandButton Caption:
If Button.Caption = "On" Then
Call SubOn
Else
Call SubOff
End If
SubOn
Sheets("MySheet").Button.Caption = "Off"
MsgBox "Button.Caption = " & Sheets("MySheet").Button.Caption ' Confirm
Caption
End SubOn
SubOff
Sheets("MySheet").Button.Caption = "On"
MsgBox "Button.Caption = " & Sheets("MySheet").Button.Caption ' Confirm
Caption
End SubOff
The rountines above work without a problem: The caption alternates between
"On" and "Off" .
However, I want the button to revert to "On" at Exit. Therefore in the
"BeforeClose" event I placed the Call SubOff.
When I click on the button and it displays "Off", and then click the "X"
(Exit application), this is the sequence of caption displays:
Initially the Button dispays "Off"
On Clicking "X" - the Button displays "On" and the MsgBox confirms that the
Caption is indeed "On".
HERE COMES THE PROBLEM:
When I Click "Ok" on the MsgBox the Caption on the Button reverts back to
"Off" and the Excel message display's the standard SAVE message YES, NO,
CANCEL
If I click "CANCEL" the Caption returns to the correct "On" display. If I
click "Yes" the worksheet is saved and Excel exits while the Button is still
displaying "Off", however when I restart the worksheet, it correctly displays
"On" when it loads.
Apparently, the caption IS being set correctly to "On", but for some reason
it momentarily reverts to the "Off" display when the Excel Exit message
displays.
Does anyone have any suggestions as to why this is happening and how to have
the Button display the correct caption when the Excel Exit message is
displayed?
Thanks
an unexpected caption display on application exit.
On CommandButton_Click two subroutines are called that alternate the
CommandButton Caption:
If Button.Caption = "On" Then
Call SubOn
Else
Call SubOff
End If
SubOn
Sheets("MySheet").Button.Caption = "Off"
MsgBox "Button.Caption = " & Sheets("MySheet").Button.Caption ' Confirm
Caption
End SubOn
SubOff
Sheets("MySheet").Button.Caption = "On"
MsgBox "Button.Caption = " & Sheets("MySheet").Button.Caption ' Confirm
Caption
End SubOff
The rountines above work without a problem: The caption alternates between
"On" and "Off" .
However, I want the button to revert to "On" at Exit. Therefore in the
"BeforeClose" event I placed the Call SubOff.
When I click on the button and it displays "Off", and then click the "X"
(Exit application), this is the sequence of caption displays:
Initially the Button dispays "Off"
On Clicking "X" - the Button displays "On" and the MsgBox confirms that the
Caption is indeed "On".
HERE COMES THE PROBLEM:
When I Click "Ok" on the MsgBox the Caption on the Button reverts back to
"Off" and the Excel message display's the standard SAVE message YES, NO,
CANCEL
If I click "CANCEL" the Caption returns to the correct "On" display. If I
click "Yes" the worksheet is saved and Excel exits while the Button is still
displaying "Off", however when I restart the worksheet, it correctly displays
"On" when it loads.
Apparently, the caption IS being set correctly to "On", but for some reason
it momentarily reverts to the "Off" display when the Excel Exit message
displays.
Does anyone have any suggestions as to why this is happening and how to have
the Button display the correct caption when the Excel Exit message is
displayed?
Thanks