PC Review


Reply
Thread Tools Rate Thread

create button on the fly in worksheet

 
 
AndrewCerritos
Guest
Posts: n/a
 
      17th Dec 2008
Hi, could anybody give me some hint or example on
how to create button on the fly on a worksheet?

AndrewCerritos
 
Reply With Quote
 
 
 
 
Gary''s Student
Guest
Posts: n/a
 
      17th Dec 2008
1. View > Toolbars > Forms
2. click on the Button button
3. draw the button on the sheet
4. assign a macro to the button
--
Gary''s Student - gsnu200820


"AndrewCerritos" wrote:

> Hi, could anybody give me some hint or example on
> how to create button on the fly on a worksheet?
>
> AndrewCerritos

 
Reply With Quote
 
Chip Pearson
Guest
Posts: n/a
 
      17th Dec 2008
Try some code like the following:

Sub CreateButton()
' create the button
Dim Btn As Excel.Button
Dim WS As Worksheet
Set WS = Worksheets("Sheet1")
Set Btn = WS.Buttons.Add(Top:=50, Left:=100, Width:=40,
Height:=20)
With Btn
.Caption = "Click Me"
.OnAction = "'" & ThisWorkbook.Name & "'!TheProc"
End With
End Sub

Sub TheProc()
' called with button is clicked.
MsgBox "Hello World"
End Sub

Cordially,
Chip Pearson
Microsoft MVP
Excel Product Group
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)


On Wed, 17 Dec 2008 12:50:08 -0800, AndrewCerritos
<(E-Mail Removed)> wrote:

>Hi, could anybody give me some hint or example on
>how to create button on the fly on a worksheet?
>
>AndrewCerritos

 
Reply With Quote
 
AndrewCerritos
Guest
Posts: n/a
 
      17th Dec 2008
Thanks. But I like to create the button on the fly from VBA only.
For example, when the book is open, it will invoke a routine to
loop through all the worksheets's name start with "ABC" and
place a button on it, including assign a macro to it.

AC

"Gary''s Student" wrote:

> 1. View > Toolbars > Forms
> 2. click on the Button button
> 3. draw the button on the sheet
> 4. assign a macro to the button
> --
> Gary''s Student - gsnu200820
>
>
> "AndrewCerritos" wrote:
>
> > Hi, could anybody give me some hint or example on
> > how to create button on the fly on a worksheet?
> >
> > AndrewCerritos

 
Reply With Quote
 
AndrewCerritos
Guest
Posts: n/a
 
      17th Dec 2008
Chip:

Thanks a lot. Works exactly as I intended.

AC

"Chip Pearson" wrote:

> Try some code like the following:
>
> Sub CreateButton()
> ' create the button
> Dim Btn As Excel.Button
> Dim WS As Worksheet
> Set WS = Worksheets("Sheet1")
> Set Btn = WS.Buttons.Add(Top:=50, Left:=100, Width:=40,
> Height:=20)
> With Btn
> .Caption = "Click Me"
> .OnAction = "'" & ThisWorkbook.Name & "'!TheProc"
> End With
> End Sub
>
> Sub TheProc()
> ' called with button is clicked.
> MsgBox "Hello World"
> End Sub
>
> Cordially,
> Chip Pearson
> Microsoft MVP
> Excel Product Group
> Pearson Software Consulting, LLC
> www.cpearson.com
> (email on web site)
>
>
> On Wed, 17 Dec 2008 12:50:08 -0800, AndrewCerritos
> <(E-Mail Removed)> wrote:
>
> >Hi, could anybody give me some hint or example on
> >how to create button on the fly on a worksheet?
> >
> >AndrewCerritos

>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Programmatically create button on Excel worksheet (vb.net) valerashylin Microsoft Excel Programming 2 19th Mar 2008 01:27 PM
How to create a drop down button on a worksheet? =?Utf-8?B?UmUgbGVhcm5pbmcgRXhjZWw=?= Microsoft Excel Worksheet Functions 3 14th Aug 2006 03:28 PM
I would like to create a button on the worksheet to work a macro =?Utf-8?B?U3RldmVk?= Microsoft Excel Programming 2 20th Feb 2006 02:26 AM
How can I create a button to save one worksheet into a new workshe =?Utf-8?B?Y291cnQ=?= Microsoft Excel Misc 2 6th Jul 2005 06:39 PM
How do I create a hyperlink from a button on a worksheet? Ian R Microsoft Excel Misc 2 4th Jun 2004 02:17 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:09 PM.