ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Running a Macro through a button vs. VBA (https://www.excelbanter.com/excel-discussion-misc-queries/156513-running-macro-through-button-vs-vba.html)

[email protected]

Running a Macro through a button vs. VBA
 
I just created a simple macro to run in one of my workbooks. When I enter
visual basic and click Run Sub/User Form, the macro works fine. However,
when I create a command button, type the name of the macro in the code for
the button, and then push the button, I get a Compile Error:Argument Not
Optional. I have several other command buttons in this workbook that work
fine. Is there any way to fix this? It's kind of a pain to have to go into
visual basic and click run instead of just clicking a button.

Thanks

Adam Bush

jlclyde

Running a Macro through a button vs. VBA
 
On Aug 30, 3:00 pm,
m wrote:
I just created a simple macro to run in one of my workbooks. When I enter
visual basic and click Run Sub/User Form, the macro works fine. However,
when I create a command button, type the name of the macro in the code for
the button, and then push the button, I get a Compile Error:Argument Not
Optional. I have several other command buttons in this workbook that work
fine. Is there any way to fix this? It's kind of a pain to have to go into
visual basic and click run instead of just clicking a button.

Thanks

Adam Bush


Adam,
Delete your button. Make sure that you have the Forms tool bar open.
Go to Toolbars, Right click, Pick Forms. Now insert the button. It
shodul pop up and ask you what Macro you want to add to the button.
You may have been using the Control Tool bar instead of the forms.
The buttons work a little differently.
Jay


[email protected]

Running a Macro through a button vs. VBA
 
Thank you very much Jay that worked perfectly.

Adam Bush

"jlclyde" wrote:

On Aug 30, 3:00 pm,
m wrote:
I just created a simple macro to run in one of my workbooks. When I enter
visual basic and click Run Sub/User Form, the macro works fine. However,
when I create a command button, type the name of the macro in the code for
the button, and then push the button, I get a Compile Error:Argument Not
Optional. I have several other command buttons in this workbook that work
fine. Is there any way to fix this? It's kind of a pain to have to go into
visual basic and click run instead of just clicking a button.

Thanks

Adam Bush


Adam,
Delete your button. Make sure that you have the Forms tool bar open.
Go to Toolbars, Right click, Pick Forms. Now insert the button. It
shodul pop up and ask you what Macro you want to add to the button.
You may have been using the Control Tool bar instead of the forms.
The buttons work a little differently.
Jay




All times are GMT +1. The time now is 11:31 PM.

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