Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

VBA macro document close crash Inventor

2 REPLIES 2
Reply
Message 1 of 3
Raf_
245 Views, 2 Replies

VBA macro document close crash Inventor

HI 

Simple VBA code to replace title block on the open document to the one from template.

Inventor keeps crashing on oTemplate.Close and I can not figure out why any idea?

 

Dim odrawdoc As DrawingDocument
Set odrawdoc = ThisApplication.ActiveDocument
If odrawdoc Is Nothing Then
MsgBox "Please Open Inventor Drawing"
closeForm
Else
Dim oTemplate As DrawingDocument
Dim oSourceTitleBlockDef As TitleBlockDefinition
Dim oNewTitleBlockDef As TitleBlockDefinition
Dim oSheet As Sheet
Set oTemplate = ThisApplication.Documents.Open("D:\Vault\Templates\Inventor\Template.idw", False)
Set oSourceTitleBlockDef = oTemplate.ActiveSheet.TitleBlock.Definition
For Each oSheet In odrawdoc.Sheets
oSheet.Activate
Set oNewTitleBlockDef = oSourceTitleBlockDef.CopyTo(odrawdoc, True)
Next
oTemplate.Close

End If

 

2 REPLIES 2
Message 2 of 3
A.Acheson
in reply to: Raf_

From this post here can you try adding the skip save Boolean? 

 

   oTemplate.Close(True)  

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 3 of 3
WCrihfield
in reply to: Raf_

Since you are opening the template 'in the background' or invisibly, you might also be able to use an alternative to Close.  You could try using ReleaseReference and Documents.CloseAll(True), like this:

oTemplate.ReleaseReference
ThisApplication.Documents.CloseAll(True)

In that CloseAll method, True means only close all of the 'unreferenced' documents.

 

 

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) 👍.

If you want and have time, I would appreciate your Vote(s) for My IDEAS :light_bulb: or you can Explore My CONTRIBUTIONS

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report