Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / New Users / May 2008

Tip: Looking for answers? Try searching our database.

Excel 2003 - VBA - Buttons

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Craig Brandt - 21 May 2008 02:59 GMT
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
Bob Phillips - 21 May 2008 09:17 GMT
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

Signature

---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

>I need someone to give me a few buzz words and point me to some reference
> work so that I can get started.
[quoted text clipped - 21 lines]
>
> Craig
Craig Brandt - 21 May 2008 15:02 GMT
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

> Sub CreateButton1()
> Dim btn1 As Object
[quoted text clipped - 52 lines]
> >
> > Craig
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.