Open VBA with a Command Button on a UserForm

geno32080

Board Regular
Joined
Jan 23, 2020
Messages
107
Office Version
  1. 2013
Platform
  1. Windows
I'm experimenting with UserForms, I built a UesrForm that loads a Main Menu Home screen when the program is launched. Since UserForms do not minimize when a Sheet is selected, you have to write in the code to include UserForm.Hide. and UserForm .Show when accessing and exiting the Sheets. I would like to be able to open the VBA Editor from a Command Button on the Main Menu. Is that possible? I have found very little about this subject on the net.
As always I thank you for any assistance.

Main Menu
1641858372152.png
(Click to open from this button)


Open This

1641858483550.png
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Maybe

Sub Button1_Click()
SendKeys "%{F11}"

End Sub

although seems kind of pointless beyond being a coding exercise. I say that because you can just press 2 keys and get the same result without objects and their code.
 
Upvote 0
There are many ways.

You could for example use this funny way :)
Application.Goto "NameOfSomeMacroLocatedInAStandardModule"

Or this easy one:
CommandBars.ExecuteMso "VisualBasic"
 
Upvote 0
Solution
Maybe

Sub Button1_Click()
SendKeys "%{F11}"

End Sub

although seems kind of pointless beyond being a coding exercise. I say that because you can just press 2 keys and get the same result without objects and their code.
I use a laptop mostly. the alt+ f11 or FN+Alt+F11, doesn't always work. That why I started searching other alternatives. The project is an experiment, Thanks for the reply, Ill give your code a shot.
 
Upvote 0
There are many ways.

You could for example use this funny way :)
Application.Goto "NameOfSomeMacroLocatedInAStandardModule"

Or this easy one:
CommandBars.ExecuteMso "VisualBasic"
Alright, thats a maybe?? Thanks.
 
Upvote 0
Alright, thats a maybe?? Thanks.
No. Those two methods should always work.

Sendkeys should always be avoided plus, it won't work with UserForms. Furthermore, using SendKeys inadvertently disables the NumLock key
 
Upvote 0
Sendkeys should always be avoided plus, it won't work with UserForms.
I've often said should be avoided with respect to Access, but I don't have a lot of experience with userforms.
using SendKeys inadvertently disables the NumLock key
Surprise, you're correct! Can fix one wrong with another wrong though: SendKeys "{NUMLOCK}" as long as a userform isn't involved, I guess.
I'd retract my OP but too late...
 
Upvote 0
I was going to ask why do I get error #5 - Invalid procedure or argument
from a command button embedded on a sheet?

Application.CommandBars.ExecuteMso "visualbasic"

Then I discovered that Excel is case sensitive?? Guess I need to learn more about that.
Yes, I have Option Compare Text at the top of the module with that code.
 
Upvote 0
Then I discovered that Excel is case sensitive?? Guess I need to learn more about that.
Yes, I have Option Compare Text at the top of the module with that code.
I think ,Option Compare Text has no bearing on the Strings of the ExecuteMso Method as there is no String comparison involved.

BTW, there is also this clean method for activating the VBE editor but requires access to the VBProject model.
Application.VBE.MainWindow.Visible = True
 
Upvote 0

Forum statistics

Threads
1,214,561
Messages
6,120,228
Members
448,951
Latest member
jennlynn

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