Excel 2003 - VBA - Buttons

  • Thread starter Thread starter Craig Brandt
  • Start date Start date
C

Craig Brandt

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
 
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)
 
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
 
Back
Top