Create cmd button on spreadsheet to run Macro

  • Thread starter Thread starter HappyDevil24
  • Start date Start date
H

HappyDevil24

Hi, anyone have this reusable code for running a macro when user clic
on a command button on spreadsheet?

Thanks
 
-----Original Message-----
Hi, anyone have this reusable code for running a macro when user click
on a command button on spreadsheet?

Thanks.


---
Message posted

.
in the command button click code use:
call macro "where macro is the name of you macro
 
Ok, well, I have a macro for importing text file to my excel
spreadsheet. Instead of adding a button to the toolbar for running this
macro (short cut to this macro), how can I create one command button
(from Control Toolbar) on the spreadsheet itself to run this macro?

Thanks, and hope this is not confusing :rolleyes:
 
click on the button on the control toolbar

rubberband a rectangle on the sheet where you want the button

Double click on the button

In the resulting code

Private Sub Commandbutton1_click()

End sub

Add you macro name
Private Sub Commandbutton1_click()
OpenTextFile
End sub

assumes your macro is named OpenTextFile

go back to the worksheet and on the control toolbox toolbar, take the sheet
out of design mode (click the upper left button on the toolbar so it doesn't
appear depressed).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top