Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Create a Macro and Name it

Status
Not open for further replies.

engineer2100

Programmer
Joined
Feb 7, 2002
Messages
285
Location
US
Hi,

Back again with another basic question (atleast to most of you folks out there).

How do i create & name a macro using an excel woksheet/book object created. I need someway to insert the macro into the worksheet/Workbook and then assign the macro name to a push button again created programatically.

Regards,
Engi
 
Tools-> Macro -> Record New Macro

Give it a descriptive name and take not of the "Store macro in: ___" Option.

If you want the macro to be available in all your workbooks whenever Excel is opened then use the Personal Macro Workbook. Or, select the current workbook you're using so it will be saved with the workbook and only available in that specific workbook.

To create a button that calls the macro...
First, open up the Control Toolbox from the View->Toolbar->__ Menu.

From the toolbar select command button. Create the button on the worksheet by dragging a selection. Right click on the button and view it's Properties. Here you may want to change the (Name) of the command button which is the name used by the code and the Caption property which is the description viewed on the worksheet.

While in Design Mode (the button to go in and out of it is in the Control Toolbox toolbar) double click on the command button and the VBE will open. You'll see something like:

Code:
Private Sub CommandButton1_Click()
	Call Macro1Name    
End Sub

Except you'll have to fill in the Call Macro1Name portion with the name of the macro you created, and instead of CommandButton1 it will have the (Name) of the command button.

Anyway, as far as doing it programmatically i'm not so sure... But hopefully this is what you meant.

HTH,

Frank
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top