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.
 

Some videos you may like

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.

ranman256

Well-known Member
Joined
Jun 17, 2014
Messages
1,900
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
 

Watch MrExcel Video

Forum statistics

Threads
1,109,334
Messages
5,528,091
Members
409,802
Latest member
joeino

This Week's Hot Topics

  • Change military grades into rank
    Afternoon all Need help with formula that will change military rank (i.e. 1, 2, 3 into Amn, A1C, SrA). Running IF formula that does not work...
  • VBA COUNTIF SOLUTION
    Hi The following are the errors spread across the several columns from E to Q ie. 13 columns across several sheets with more than 500 rows per...
  • INSERT ROW WITH SPECIFIS TEXT IN A COLUMN
    Hi All! How can identify that that the row to be inserted has to be inserted before 1st row with specific text in column F. If I record the...
  • Auto-Create a monthly Sign in sheet for preschool students
    The image below is what each page looks like. Above is space for the "Child Name" "Month" "Class" School days are obviously Monday-Friday but...
  • VBA vlookup multiple results
    Hi folks, Hopefully someone out there can help. I have a list to vlookup which works (ish). the lookup only picks up the first instance of the...
  • Extract values for earliest/latest times
    I am trying to put together a formula to get the earliest start time, the latest end time from column A for each person in Column B-F without the...
Top