Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
PJ PJ is offline
external usenet poster
 
Posts: 112
Default Macro to add button w/code to new worksheet

I'm using an excel file which compiles different reports into one monthly
report file. I have a button that I want added to one of the sheets in the
monthly file. The script recorder gave me the following information to add
the button, but I can't figure out how to get it to assign my existing code
to the new button.

Sheets("Sheet1").Select
ActiveSheet.OLEObjects.Add(ClassType:="Forms.Comma ndButton.1",
Link:=False _
, DisplayAsIcon:=False, Left:=10.5, Top:=55.5, Width:=79.5, Height:= _
31.5).Select
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Macro to add button w/code to new worksheet

How about:

Sub Macro1()
ActiveSheet.Buttons.Add(252.75, 90.75, 94.5, 45).Select
Selection.OnAction = "dural"
End Sub


with

Sub dural()
MsgBox ("Hello World")
End Sub
--
Gary''s Student - gsnu200834


"PJ" wrote:

I'm using an excel file which compiles different reports into one monthly
report file. I have a button that I want added to one of the sheets in the
monthly file. The script recorder gave me the following information to add
the button, but I can't figure out how to get it to assign my existing code
to the new button.

Sheets("Sheet1").Select
ActiveSheet.OLEObjects.Add(ClassType:="Forms.Comma ndButton.1",
Link:=False _
, DisplayAsIcon:=False, Left:=10.5, Top:=55.5, Width:=79.5, Height:= _
31.5).Select

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Macro to add button w/code to new worksheet

I believe that with that type of button you can turn on design mode in VBE
then right click the buttonAssign Macro which brings up the Macro dialog box
where you click on the macro you want the button to run, then click OK when
it appears in the top window of the dialog box. Click out of design mode and
you are set.

"PJ" wrote:

I'm using an excel file which compiles different reports into one monthly
report file. I have a button that I want added to one of the sheets in the
monthly file. The script recorder gave me the following information to add
the button, but I can't figure out how to get it to assign my existing code
to the new button.

Sheets("Sheet1").Select
ActiveSheet.OLEObjects.Add(ClassType:="Forms.Comma ndButton.1",
Link:=False _
, DisplayAsIcon:=False, Left:=10.5, Top:=55.5, Width:=79.5, Height:= _
31.5).Select

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
Macro code behind button bcm2 Excel Worksheet Functions 1 January 13th 10 06:13 PM
Enable or Disable Forms Button on a worksheet from code Corey Excel Programming 1 November 5th 07 12:43 AM
Command button to toggle worksheet event code on / off? Fred[_2_] Excel Discussion (Misc queries) 15 July 31st 07 11:50 AM
How do I code VBA to hit button on a different worksheet? [email protected] Excel Programming 5 August 8th 06 09:39 PM
c# code to add button control to the worksheet!!!! .NetProf Excel Programming 0 January 30th 06 04:45 AM


All times are GMT +1. The time now is 04:41 AM.

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"