Run Macro Unload After Run

Programming and macros
User avatar
Rob
Posts: 128
Joined: Mon Mar 08, 2021 3:46 pm
Answers: 2
Location: Mighty Glossop, UK
x 787
x 207
Contact:

Run Macro Unload After Run

Unread post by Rob »

I'm messing about and have created a macro to run all attached macros.

I started with ISldWorks::RunAttachedMacro method

The macros run as expected but I noticed that multiple copies of the macro were open in the VBA Editor.

I then switched to ISldWorks::RunMacro2 method as I noticed there is the unload after run option but it didn't make any difference.

image.png

Seems dodgy to me - or am I missing something?
colt
Posts: 54
Joined: Tue Mar 30, 2021 5:43 pm
Answers: 0
x 14
x 22

Re: Run Macro Unload After Run

Unread post by colt »

I get some different results.
persistent launcher:

Code: Select all

Public swApp As SldWorks.SldWorks
Sub main()
    Set swApp = Application.SldWorks
    UserForm1.Show
End Sub

'with button to launch

Private Sub CommandButton1_Click()
    Dim r As Boolean
    Dim err As Long
    r = swApp.RunMacro("Y:\Downloads\Macro1.swp", "Macro11", "Main")
    'r = swApp.RunMacro2("Y:\Downloads\Macro1.swp", "Macro11", "Main", swRunMacroOption_e.swRunMacroUnloadAfterRun, err)
End Sub
the macro:

Code: Select all

Sub main()
    Debug.Print ("subMacro")
End Sub
If I run with RunMacro2 it seems to properly unload from the side panel. RunMacro leaves it there as expected. Might have to do with the content of your child macro, maybe an open file reference or something. What happens if you simplify the launched macro?
User avatar
Rob
Posts: 128
Joined: Mon Mar 08, 2021 3:46 pm
Answers: 2
Location: Mighty Glossop, UK
x 787
x 207
Contact:

Re: Run Macro Unload After Run

Unread post by Rob »

Thanks for looking @colt@

I was still in the testing stage so my code was almost identical to yours, except it was a msgbox and a rude word ;p
Post Reply