Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default create button on the fly in worksheet

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

AndrewCerritos
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default create button on the fly in worksheet

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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default create button on the fly in worksheet

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
wrote:

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

AndrewCerritos

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default create button on the fly in worksheet

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

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default create button on the fly in worksheet

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
wrote:

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

AndrewCerritos


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I create button to printout worksheet range in excel 2007? apaicello Excel Discussion (Misc queries) 1 February 26th 10 08:26 PM
Programmatically create button on Excel worksheet (vb.net) valerashylin Excel Programming 2 March 19th 08 01:27 PM
How to create a drop down button on a worksheet? Re learning Excel Excel Worksheet Functions 3 August 14th 06 03:28 PM
I would like to create a button on the worksheet to work a macro Steved Excel Programming 2 February 20th 06 02:26 AM
How can I create a button to save one worksheet into a new workshe court Excel Discussion (Misc queries) 2 July 6th 05 06:39 PM


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

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"