I have a macro that runs perfectly while testing, but, when i try to run it outside of the vba screen it does nothing. Why?
Please note: code will NOT automatically start with Sub main(). It starts with whatever sub takes no arguments that is last in the module.
If you map to a shortcut key you can specifiy the starting subroutine. If you just run with Tools->Macro->Run you cannot specify the starting sub.
Please see How to tell vb which sub to run first
Set a button to this macro and set the sub you want to start first.
Hi, thanks for your answer,
how can i set which sub will be the "start"?
When you set the button, you can choose the required sub in the drop down menu.
I'm not finding this window. Can i do this in the 2016 version?
In VBA the Sub main() is the starting point. In it, refer to the Sub or Function to be execute. E.g.
Hi, Thank you!
Oh, now i get it, and about the "button" can i set a keyboard shorcut to run the macro?
If you have created a button for the macro, you can assign a shortcut to it.
Thank you, it's working now.
Just one last question:
Every one of my subs has a "main" before the name, but in the vba window there is no main. Is that why i couldn't set the start just by renaming one of the subs to "main"?
Oh nevermind, it was because my macro's name was Main. LOL sorry, i'm not very experienced in macros
You're right, I just tried it. In this case, the answer is incorrect and should be canceled. I haven't noticed it probably because I always use functions to return success or failure via bool. Thanks a lot.
So, basically, the starting sub will be the sub that has no variable declarations
It's the last sub with no arguments.
In the above, Foo will be what is executed because it's the last sub with no arguments.
That is unless you explicitly state which to start via a macro button or the runmacro2 method
Matt Bieringer wrote: That is unless you explicitly state which to start via a macro button or the runmacro2 method
Matt Bieringer wrote:
Retrieving data ...