How do I view/edit code on Excel 2003 Worksheet Command Button

U

u473

I do not remember how I access the code behind my Command Button on my
worksheet.
I am using Excel 2003.
I have searched in Tools>Macros, Sheet1>View Code without success.
I know that in Excel 2007 you have to go in the Developer tab, but I
am using 2003.
Help appreciated.
J.P.
 
D

Dave Peterson

You can rightclick on the worksheet tab and select View Code.

You'll be in the sheet module for that worksheet.
 
U

u473

Thank you for your answer, but I did that before and I saw the codes
associated to that worksheet,
but nowhere do I see a CommandButtonClick() code.
I do not know where else to look
 
D

Dave Peterson

The commandbutton is placed on the worksheet, right?

If yes, then the code associated with that commandbutton will be in that sheet's
module.

But maybe you're not using commandbuttons from the control toolbox toolbar?
Maybe you're using buttons from the Forms toolbar???

If that's the case, then the code should be in a general module -- not behind a
worksheet.

=======
Another way to get to the sheet module (where the code for the commandbutton
will be).

Show the control toolbox toolbar.
Click on the Design mode icon.
Doubleclick your commandbutton.

You should be in that sheet's code module and directly in the
commmandbutton1_click() procedure.
 
U

u473

Issue not resolved but I learned something from your previous post and
from the following Contexture.com article on the subject.
,,,,,,,,,,,,,,,,,,,,,,
3. Buttons to Run Excel Macros

When a button is drawn onto a sheet the assign macro is not displayed.
When right-clicking on the button the "Assign Macro" context menu item
is not present.

There are buttons from the Forms toolbar and there are buttons from
the Control Toolbox. If "Assign Macro" is not an option then it's from
the Control Toolbox.

Choose "View code" and call your macro from it like this:

Private Sub CommandButton1_Click()
Call Macro1
End Sub
.......................
So I created a simple worksheet with a simple macro, which worked
then I created a button from the button icon on my menu toolbar (not
from the toolbox)
Then I right-clicked my button to assign my macro, and it worked
fine.
But I could not find anywhere the commmandbutton1_click() procedure,
whether in
the General Module or the Worksheet.
As you guessed, I was not using the commandbuttons from the control
toolbox toolbar, but using buttons from the Forms toolbar???
So I created another button for the same macro using the control
toolbox toolbar.
When I right-clicked it, I could see the View Code and place my Call
in the CommandButton1_Click() and it worked and I am satisfied. Lesson
Learned.
However, I still would be curious on how to access the code behind a
button created from the Forms Toolbar.
Thank you for your help.
J.P.
 
G

Gord Dibben

After assigning a macro to the Forms button, right-click on the button and
"Assign Macro"

Macro dialog will open with the assigned macro name highlighted.

Click on "Edit" to see the code.


Gord Dibben MS Excel MVP
 
U

u473

Ok, so you are telling me that from a Forms button I cannot expect to
see a CommandButton1_Click() procedure. Lesson Learned.
Thank you for your help.
J.P>
 
D

Dave Peterson

The code for the buttons from the Forms toolbar will be in a General module.

The macro could be named any legal name.

You could call it "commandbutton1_click" if you wanted -- even if the button
were named "hitherefromJP".

But I wouldn't do that. It may not confuse excel, but it would confuse me and
it may confuse whoever owns the workbook after I share it with them.
 
Joined
Oct 6, 2015
Messages
1
Reaction score
0
I do not remember how I access the code behind my Command Button on my
worksheet.
I am using Excel 2003.
I have searched in Tools>Macros, Sheet1>View Code without success.
I know that in Excel 2007 you have to go in the Developer tab, but I
am using 2003.
Help appreciated.
J.P.
If the worksheet is protected, on the tab at the bottom , click unprotect. Now right click the command button --> assign macro --> edit. This should take you the sub running behind the command button
 

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

Top