![]() |
|
|
Welcome to the { mindfrost82.com } forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact contact us. |
|
|||||||
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
|
|||
|
Excel 2003 - VBA - Buttons
I need someone to give me a few buzz words and point me to some reference
work so that I can get started. I want to place several buttons on a worksheet that will help the user move around. I need to create a button then upon activation change the Caption and execute a macro that will create a button on another sheet. upon activation of this button, I will execute a macro and at the end of the macro, delete the button. In order to work with the button I need to name it then address it to make the changes and ultimately delete it. Here is the code I used to create the first button: ActiveSheet.Buttons.Add(1245, 16, 64, 16).Select Selection.Caption = "AutoFocus On" Selection.Name = "AutoFocusBut" Selection.OnAction = "FocusOn" In the routine "FocusOn" I want to look at the caption to determine the needed activity, then change the caption. Up to now the button has been selected. It will not be when I come back. How do I select the button, and test the caption. I thought I knew, but obviously I am missing something. References anyone? Craig |
|
|||
|
Re: Excel 2003 - VBA - Buttons
Sub CreateButton1()
Dim btn1 As Object Set btn1 = ActiveSheet.Buttons.Add(1245, 16, 64, 16) With btn1 .Caption = "AutoFocus On" .Name = "AutoFocusBut" .OnAction = "FocusOn" End With End Sub Sub FocusOn() Dim btn2 As Object Set btn2 = ActiveSheet.Buttons.Add(1000, 16, 64, 16) With btn2 .Caption = "Button2" .Name = "Button2" .OnAction = "RunButton2" End With ActiveSheet.Buttons("AutoFocusBut").Caption = "Changed" End Sub Sub RunButton2() ActiveSheet.Buttons("AutoFocusBut").Delete End Sub -- --- HTH Bob (there's no email, no snail mail, but somewhere should be gmail in my addy) "Craig Brandt" <brandtcraig@att.net> wrote in message news:gmLYj.4183$ah4.2147@flpi148.ffdc.sbc.com... >I need someone to give me a few buzz words and point me to some reference > work so that I can get started. > > I want to place several buttons on a worksheet that will help the user > move > around. I need to create a button then upon activation change the Caption > and execute a macro that will create a button on another sheet. upon > activation of this button, I will execute a macro and at the end of the > macro, delete the button. > In order to work with the button I need to name it then address it to make > the changes and ultimately delete it. > > Here is the code I used to create the first button: > ActiveSheet.Buttons.Add(1245, 16, 64, 16).Select > Selection.Caption = "AutoFocus On" > Selection.Name = "AutoFocusBut" > Selection.OnAction = "FocusOn" > In the routine "FocusOn" I want to look at the caption to determine the > needed activity, then change the caption. Up to now the button has been > selected. It will not be when I come back. How do I select the button, and > test the caption. > I thought I knew, but obviously I am missing something. > References anyone? > > Craig > > > |
|
|||
|
Re: Excel 2003 - VBA - Buttons - Thanks
Bob:
After reviewing your code, I think part of my problem was that I was on a different sheet when I tried to address the button plus I didn't use the "Set" code. Thanks much for the input. Craig "Bob Phillips" <bob.NGs@somewhere.com> wrote in message news:enwmwsxuIHA.2208@TK2MSFTNGP04.phx.gbl... > Sub CreateButton1() > Dim btn1 As Object > Set btn1 = ActiveSheet.Buttons.Add(1245, 16, 64, 16) > With btn1 > > .Caption = "AutoFocus On" > .Name = "AutoFocusBut" > .OnAction = "FocusOn" > End With > > End Sub > > Sub FocusOn() > Dim btn2 As Object > > Set btn2 = ActiveSheet.Buttons.Add(1000, 16, 64, 16) > With btn2 > > .Caption = "Button2" > .Name = "Button2" > .OnAction = "RunButton2" > End With > > ActiveSheet.Buttons("AutoFocusBut").Caption = "Changed" > > End Sub > > Sub RunButton2() > ActiveSheet.Buttons("AutoFocusBut").Delete > End Sub > > > -- > --- > HTH > > Bob > > > (there's no email, no snail mail, but somewhere should be gmail in my addy) > > > > "Craig Brandt" <brandtcraig@att.net> wrote in message > news:gmLYj.4183$ah4.2147@flpi148.ffdc.sbc.com... > >I need someone to give me a few buzz words and point me to some reference > > work so that I can get started. > > > > I want to place several buttons on a worksheet that will help the user > > move > > around. I need to create a button then upon activation change the Caption > > and execute a macro that will create a button on another sheet. upon > > activation of this button, I will execute a macro and at the end of the > > macro, delete the button. > > In order to work with the button I need to name it then address it to make > > the changes and ultimately delete it. > > > > Here is the code I used to create the first button: > > ActiveSheet.Buttons.Add(1245, 16, 64, 16).Select > > Selection.Caption = "AutoFocus On" > > Selection.Name = "AutoFocusBut" > > Selection.OnAction = "FocusOn" > > In the routine "FocusOn" I want to look at the caption to determine the > > needed activity, then change the caption. Up to now the button has been > > selected. It will not be when I come back. How do I select the button, and > > test the caption. > > I thought I knew, but obviously I am missing something. > > References anyone? > > > > Craig > > > > > > > > |
![]() |
|
| Thread Tools | Search this Thread |
| Display Modes | |
|
|