View/(Navigte to) the code module of a command button of a specific userform, using vba

Sanmrxl

New Member
Joined
Aug 1, 2007
Messages
36
I currently landed up with a requirement, which is , to jump/navigate
to the code module view
of a command button
of a specific userform.

While it is easy
to view the code window
of the sub modules, using the Application.goto,
it does not appear to be so ,
for the userform code window.

The challenge here to me, seems to be on 2 things.

1) The name of the userform code module window.

2) While the sub modules in VBE, are all unique,
but with the userforms, it does not appear so.

For example -

" Private Sub CommandButton1_Click() "
can exist for any number of userforms.

So putting my requirements more clearly.

In a vba project
with 2 userforms, Userform1 and Userform2,
both having a commandbutton1,
and both buttons having click events
(but diff codes for each button, under the click event),

I wish to view the code under
Private Sub CommandButton1_Click()
for Userform1
using vba code.


Thanks in advance.
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
put your shared code into a module.

Code:
sub RunMyCode()
    msgbox "hello world"
end sub

now it can be called from any form...
Code:
'IN FORM 1
sub command1_click()
   RunMyCode
end sub

'IN FORM 2
sub command2_click()
   RunMyCode
end sub
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,219
Members
452,619
Latest member
Shiv1198

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top