Message 1 of 4
copy drawing resources vba randomly crashing

Not applicable
04-17-2018
07:07 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
It could have something to do with the drawing itself - maybe I can turn errors back on in here....
Public Sub CopyDrawingResources() If ThisApplication.ActiveDocument Is Nothing Then Exit Sub Else If ThisApplication.ActiveDocument.DocumentType = kDrawingDocumentObject Then Dim InvDoc As Document Set InvDoc = ThisApplication.ActiveDocument Else Exit Sub End If End If Dim SourceDoc As DrawingDocument Set SourceDoc = ThisApplication.Documents.Open("J:\Inventor Files\Templates\LM Drawing 8_5x11.idw", False) On Error Resume Next For Each Item In InvDoc.SheetFormats Item.Delete Next For Each Item In InvDoc.BorderDefinitions If Item.IsReferenced = False Then Item.Delete Next For Each Item In InvDoc.TitleBlockDefinitions If Item.IsReferenced = False Then Item.Delete Next For Each Item In InvDoc.SketchedSymbolDefinitions If Item.IsReferenced = False Then Item.Delete Next For Each Item In SourceDoc.BorderDefinitions Set TargetBorder = Item.CopyTo(InvDoc, True) Next For Each Item In SourceDoc.TitleBlockDefinitions Set TargetHeader = Item.CopyTo(InvDoc, True) Next For Each Item In SourceDoc.SketchedSymbolDefinitions Set TargetSymbol = Item.CopyTo(InvDoc, True) Next For Each Item In SourceDoc.SheetFormats 'Caution: this creates a new copy of the TitleBlock used for EACH SheetFormat, 'regardless if the TitleBlockDefinition already exists or not!!! Set TargetSheet = Item.CopyTo(InvDoc) Next On Error GoTo 0 SourceDoc.ReleaseReference SourceDoc.Close (True) Set SourceDoc = Nothing End Sub
here's where it's bombing right now, invalid procedure call or argument
- if I leave the error skipping on, and delete some older templates and borders prior to running this, it will run without crashing.
It looks like it's trying to delete stuff earlier on in the code, maybe I can force this somehow, ie: remove it from all drawing sheets, then the tree, then copy the new stuff.