-
Re: Main Subprocedure
Deepak Gupta Aug 15, 2018 12:39 PM (in response to Marcos Rodríguez)How are you running this macro? Try putting the main in the last i.e. make it the bottom most sub and check.
-
Re: Main Subprocedure
Marcos Rodríguez Aug 15, 2018 12:47 PM (in response to Marcos Rodríguez)Hi Deepak,
I'm running it from the normal macro toolbox, I think I've the solution. When I save the macro, before close it, the 'Main' Subprocedure has to be selected.
you can try it, the macro is attach to first question.
Regards.
-
Re: Main Subprocedure
Deepak Gupta Aug 15, 2018 2:38 PM (in response to Marcos Rodríguez)Marcos Rodríguez wrote:
I'm running it from the normal macro toolbox
Why not set a macro button and set your required sub in that. This saves timing in browsing the macro and also run the correct sub
-
Re: Main Subprocedure
Marcos Rodríguez Aug 15, 2018 5:38 PM (in response to Deepak Gupta)Don't know how to do that, could you send me a link or explain it a little bit further, please?
Cheers.
-
Re: Main Subprocedure
Deepak Gupta Aug 16, 2018 12:01 AM (in response to Marcos Rodríguez)Marcos Rodríguez wrote:
Don't know how to do that, could you send me a link or explain it a little bit further, please?
-
-
-
Re: Main Subprocedure
Josh Brady Aug 15, 2018 5:48 PM (in response to Marcos Rodríguez)Marcos Rodríguez wrote:
Hi Deepak,
I'm running it from the normal macro toolbox, I think I've the solution. When I save the macro, before close it, the 'Main' Subprocedure has to be selected.
you can try it, the macro is attach to first question.
Regards.
A robust method (IMHO) is to make your subs have arguments. You don't have to actually use them, and you can even make them optional. The macro will not start with any sub that takes an argument (optional or not)
sub main()
'do some stuff
Call SomeOtherSubThatDoesntNeedArguments
'OK now do more stuff
end sub
sub SomeOtherSubThatDoesntNeedArguments(Optional DummyArgumentAnyway as Boolean)
'this sub's code
end sub
-
Re: Main Subprocedure
Marcos Rodríguez Aug 15, 2018 6:02 PM (in response to Josh Brady)Hi Josh,
Thanks, I'd just realized of that, I had to introduce a fake argument .
Cheers
-
Re: Main Subprocedure
Artem Taturevych Aug 15, 2018 8:57 PM (in response to Marcos Rodríguez)You can look at another option suggested by Solid Air at this post: Running my macro from the start-screen starts with wrong module/sub
-
Re: Main Subprocedure
Josh Brady Aug 15, 2018 9:49 PM (in response to Artem Taturevych)Artem Taturevych wrote:
You can look at another option suggested by Solid Air at this post: Running my macro from the start-screen starts with wrong module/sub
Yes, the inimitable Deepak actually had that one right out the gate... Although I think you mentioned that sometimes it seems not to work. I see you mentioned the dummy arguments... Not sure how C # works, but with VBA if you make the dummy variable optional then you don't actually have to use it when you call the function... Only the declaration of the sub is different.
-
Re: Main Subprocedure
Artem Taturevych Aug 15, 2018 10:06 PM (in response to Josh Brady)Yes, I was sure it didn't work for older sw versions, but I have done some tests for SW 2017 and SW 2018 and found that this is always the last parameterless method of the last module (I do not have old SW versions anymore so cannot test there: perhaps this was a behaviour of VBA6 and it changed when they switched to VBA7 or perhaps I was just wrong and it always behaved this way - not sure). Basically when you edit the macro you will have a cursor on this method. I didn't managed to break this behaviour so I assume Solid Air was right in his findings. I still not fully like this approach as it doesn't look 'rock solid' to me. I still prefer dummy parameter. BTW. Great idea with optional dummy parameter for VBA macro!
-
-
-
-
-