Is it possible to run VBA code when i switch the active document?

Is it possible to run VBA code when i switch the active document?

torben_schroederXDK86
Contributor Contributor
410 Views
2 Replies
Message 1 of 3

Is it possible to run VBA code when i switch the active document?

torben_schroederXDK86
Contributor
Contributor

Hey.

 

I have created a userform which helps with saving and exporting the currently active document as needed.

Right now in the userform_initialize sub i have it fill all the textboxes, lables and so on accordingly to the filename and iproperties etc.

I have made it so i can interact with inventor while having the userform open. I can switch the document while its open.

Now i want to know if its possible to re-run the userform_initialize sub when i switch the active document. If so, how? Or are there any other ways around?

 

(yes i am lazy, thats why i dont want to reopen the userform everytime i want to export/save a new file)

0 Likes
Accepted solutions (1)
411 Views
2 Replies
Replies (2)
Message 2 of 3

Michael.Navara
Advisor
Advisor

In general it is possible, but I recommend you to use VB.NET add-in instead of VBA. There are much more possibilities to handle required events like ApplicationEvents.OnActivateDocumentApplicationEvents.OnNewEditObject, etc.

Also DockableWindow can be useful object.

0 Likes
Message 3 of 3

Frederick_Law
Mentor
Mentor
Accepted solution

Can't be too lazy.

Add a button in the from to "reload".

 

I used a form to launch macros, 20 years ago:

Macro-05.jpg

 

Now most of them are addin with icon in Ribbon.

 

Also using iLogic:

iLogicRules-01.jpg

0 Likes