ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Macro to add button w/code to new worksheet (https://www.excelbanter.com/excel-programming/424318-macro-add-button-w-code-new-worksheet.html)

PJ

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

Gary''s Student

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


JLGWhiz

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



All times are GMT +1. The time now is 02:53 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com