<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: VBA Replace title block definitions in drawing from template file in Inventor Programming Forum</title>
    <link>https://forums.autodesk.com/t5/inventor-programming-forum/vba-replace-title-block-definitions-in-drawing-from-template/m-p/3913485#M130951</link>
    <description>&lt;P&gt;Thanks for the tip. I was able to switch back to my original code with that argument added and it works great. Well other than the occasional error adding the title block back in on multisheet drawings. Only seems to happen on a few when I don't activate sheets. Might just have to have it activate all sheets, it's not that much slower even on larger assembly drawings. Or after writing all of that I went and added an on error, which activates the current sheet on an error. Which is doing the trick nicely.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;About the addin, I see two reasons I probably won't start using them in general. From what I read this addin automatically updates drawings when opened, definitely don't want to do that since certain things have edited title blocks. For addins in general it seems you have to install them, which I figure the others in my department wouldn't do. Most of them won't even manually replace a title block, lol.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Final code (for now)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Sub Update_TitleBlock()
    On Error GoTo ErrHandler:
    
    Dim odrawdoc As DrawingDocument
    Set odrawdoc = ThisApplication.ActiveDocument

    If (odrawdoc.DocumentType &amp;lt;&amp;gt; kDrawingDocumentObject) Then Exit Sub
    
    Dim oTemplate As DrawingDocument
    Dim oSourceTitleBlockDef As TitleBlockDefinition
    Dim oNewTitleBlockDef As TitleBlockDefinition
    Dim oSheet As Sheet
    Dim titlename As String
    
    Set oSheet = odrawdoc.ActiveSheet
    
    If (oSheet.TitleBlock.name = "ASSY") Then
        titlename = "ASSY"
        fname = "D_ASSY.idw"
    ElseIf (oSheet.TitleBlock.name = "TOLERANCE") Then
        titlename = "TOLERANCE"
        fname = "D_DET.idw"
    Else:
        MsgBox "This drawing has an unknown title block"
        Exit Sub
    End If
    
    Set oTemplate = ThisApplication.Documents.Open(ThisApplication.FileOptions.TemplatesPath &amp;amp; fname, False)
    Set oSourceTitleBlockDef = oTemplate.ActiveSheet.TitleBlock.Definition
    Set oNewTitleBlockDef = oSourceTitleBlockDef.CopyTo(odrawdoc, True)
    
    ' Iterate through the sheets.
    For Each oSheet In odrawdoc.Sheets
        'oSheet.Activate if error occurs
        oSheet.TitleBlock.Delete
        Call oSheet.AddTitleBlock(oNewTitleBlockDef)
    Next
    oTemplate.Close
    
    Exit Sub
ErrHandler:
    oSheet.Activate
    Resume
End Sub&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 08 May 2013 11:49:50 GMT</pubDate>
    <dc:creator>pball</dc:creator>
    <dc:date>2013-05-08T11:49:50Z</dc:date>
    <item>
      <title>VBA Replace title block definitions in drawing from template file</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/vba-replace-title-block-definitions-in-drawing-from-template/m-p/3911517#M130945</link>
      <description>&lt;P&gt;I have some code to replace the current title block with a title block from a template file. I just don't like how it adds a new title block definition named "copy of titleblock". I'd like to delete or replace the current title block definition so only the newly added one is listed.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Sub test()
    Dim odrawdoc As DrawingDocument
    Set odrawdoc = ThisApplication.ActiveDocument

    If (odrawdoc.DocumentType &amp;lt;&amp;gt; kDrawingDocumentObject) Then Exit Sub
    
    Dim oTemplate As DrawingDocument
    Dim oSourceTitleBlockDef As TitleBlockDefinition
    Dim oNewTitleBlockDef As TitleBlockDefinition
    Dim oSheet As Sheet
    
    Set oTemplate = ThisApplication.Documents.Open(ThisApplication.FileOptions.TemplatesPath &amp;amp; "template.idw", False)
    Set oSourceTitleBlockDef = oTemplate.ActiveSheet.TitleBlock.Definition
    Set oNewTitleBlockDef = oSourceTitleBlockDef.CopyTo(odrawdoc)
    
    ' Iterate through the sheets.
    For Each oSheet In odrawdoc.Sheets
        oSheet.Activate
        oSheet.TitleBlock.Delete
        Call oSheet.AddTitleBlock(oNewTitleBlockDef)
    Next
    oTemplate.Close
End Sub&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;I'm just being picky at this point, but I don't want a buildup of title block definitions. We reuse drawings all the time which is why a simple method of updating a title block would be nice. I can just imagine in some years time after a title block update or two there are 20 "copy of copy of copy of .................. titleblock" listed in a drawing file.&lt;/P&gt;</description>
      <pubDate>Tue, 07 May 2013 11:38:50 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/vba-replace-title-block-definitions-in-drawing-from-template/m-p/3911517#M130945</guid>
      <dc:creator>pball</dc:creator>
      <dc:date>2013-05-07T11:38:50Z</dc:date>
    </item>
    <item>
      <title>Re: VBA Replace title block definitions in drawing from template file</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/vba-replace-title-block-definitions-in-drawing-from-template/m-p/3911762#M130946</link>
      <description>&lt;P&gt;You could try something like this (I didn't test it, just edited what you pasted):&lt;/P&gt;&lt;PRE&gt;Sub test()
    Dim odrawdoc As DrawingDocument
    Set odrawdoc = ThisApplication.ActiveDocument

    If (odrawdoc.DocumentType &amp;lt;&amp;gt; kDrawingDocumentObject) Then Exit Sub
    
    Dim oTemplate As DrawingDocument
    Dim oSourceTitleBlockDef As TitleBlockDefinition
    Dim oNewTitleBlockDef As TitleBlockDefinition
    Dim oSheet As Sheet
    
    Set oTemplate = ThisApplication.Documents.Open(ThisApplication.FileOptions.TemplatesPath &amp;amp; "template.idw", False)
    Set oSourceTitleBlockDef = oTemplate.ActiveSheet.TitleBlock.Definition

    ' Iterate through the sheets.
    For Each oSheet In odrawdoc.Sheets
        oSheet.Activate
        oSheet.TitleBlock.Delete
    Next
    Set oNewTitleBlockDef = oSourceTitleBlockDef.CopyTo(odrawdoc)
    For Each oSheet In odrawdoc.Sheets
        oSheet.Activate
        Call oSheet.AddTitleBlock(oNewTitleBlockDef)
    Next

    oTemplate.Close
End Sub&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;I'm not sure if you need to activate each sheet before you delete/add titleblocks, have you tried using this with the oSheet.Activate commented out? It will run much faster if you can get away without it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 May 2013 14:05:42 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/vba-replace-title-block-definitions-in-drawing-from-template/m-p/3911762#M130946</guid>
      <dc:creator>mrattray</dc:creator>
      <dc:date>2013-05-07T14:05:42Z</dc:date>
    </item>
    <item>
      <title>Re: VBA Replace title block definitions in drawing from template file</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/vba-replace-title-block-definitions-in-drawing-from-template/m-p/3912079#M130947</link>
      <description>&lt;P&gt;That's just about perfect there. I just had to add a line to delete the title block definition between the part removing the current title block and then copying the new one in. After looking over your code and playing around some more it hit me you have to remove the current title block from all sheets before you can delete it, which was my problem with what I tried before.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So the last part ends up like this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt; Sub Update_TitleBlock()&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim odrawdoc As DrawingDocument&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Set odrawdoc = ThisApplication.ActiveDocument&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; If (odrawdoc.DocumentType &amp;lt;&amp;gt; kDrawingDocumentObject) Then Exit Sub&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim oTemplate As DrawingDocument&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim oSourceTitleBlockDef As TitleBlockDefinition&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim oNewTitleBlockDef As TitleBlockDefinition&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim oSheet As Sheet&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim titlename As String&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Set oSheet = odrawdoc.ActiveSheet&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; If (oSheet.TitleBlock.name = "ASSY") Then&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; titlename = "ASSY"&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fname = "D_ASSY.idw"&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ElseIf (oSheet.TitleBlock.name = "TOLERANCE") Then&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; titlename = "TOLERANCE"&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fname = "D_DET.idw"&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Else:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; MsgBox "This drawing has an unknown title block"&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Exit Sub&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; End If&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Set oTemplate = ThisApplication.Documents.Open(ThisApplication.FileOptions.TemplatesPath &amp;amp; fname, False)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Set oSourceTitleBlockDef = oTemplate.ActiveSheet.TitleBlock.Definition&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ' Iterate through the sheets.&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; For Each oSheet In odrawdoc.Sheets&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; oSheet.TitleBlock.Delete&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Next&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; odrawdoc.TitleBlockDefinitions.Item(titlename).Delete&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Set oNewTitleBlockDef = oSourceTitleBlockDef.CopyTo(odrawdoc)&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; For Each oSheet In odrawdoc.Sheets&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Call oSheet.AddTitleBlock(oNewTitleBlockDef)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Next&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; oTemplate.Close&lt;BR /&gt;End Sub&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;There is also a bit of extra I didn't include before, which works with the part or assembly title block.&lt;/P&gt;</description>
      <pubDate>Tue, 07 May 2013 18:51:52 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/vba-replace-title-block-definitions-in-drawing-from-template/m-p/3912079#M130947</guid>
      <dc:creator>pball</dc:creator>
      <dc:date>2013-05-07T18:51:52Z</dc:date>
    </item>
    <item>
      <title>Re: VBA Replace title block definitions in drawing from template file</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/vba-replace-title-block-definitions-in-drawing-from-template/m-p/3912088#M130948</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/1041683"&gt;@pball&lt;/a&gt; wrote:&lt;BR /&gt;&lt;P&gt;I just had to add a line to delete the title block definition between the part removing the current title block and then copying the new one in.&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Oops, looks like I cut it and forgot to paste it. I'm glad you got it working, anyways.&lt;/P&gt;&lt;P&gt;It's a good rule of thumb with these things to have your code emulate what you would be doing through the UI. Generally, if you can't do it through the UI then you'll get an error when you try to do it with code. In fact, I would even recommend for the future that you do a trial run of something you want to code and document every step you have to take, as your code will have to follow a similar sequence and will have the same limitations.&lt;/P&gt;</description>
      <pubDate>Tue, 07 May 2013 19:01:26 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/vba-replace-title-block-definitions-in-drawing-from-template/m-p/3912088#M130948</guid>
      <dc:creator>mrattray</dc:creator>
      <dc:date>2013-05-07T19:01:26Z</dc:date>
    </item>
    <item>
      <title>Re: VBA Replace title block definitions in drawing from template file</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/vba-replace-title-block-definitions-in-drawing-from-template/m-p/3912117#M130949</link>
      <description>&lt;P&gt;I always think out my scripts, some more than others though. Smaller things like this I tend to fly by the seat of my pants (which isn't always the best), but I've made some long flow chart like things for some of my larger scripts. Really helps plans the logic and finding common parts that can be turned into functions and such.&lt;/P&gt;</description>
      <pubDate>Tue, 07 May 2013 19:42:52 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/vba-replace-title-block-definitions-in-drawing-from-template/m-p/3912117#M130949</guid>
      <dc:creator>pball</dc:creator>
      <dc:date>2013-05-07T19:42:52Z</dc:date>
    </item>
    <item>
      <title>Re: VBA Replace title block definitions in drawing from template file</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/vba-replace-title-block-definitions-in-drawing-from-template/m-p/3912585#M130950</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;you do not need to delete the tilteblock&lt;/P&gt;&lt;P&gt;there is a replace function&lt;/P&gt;&lt;P&gt;True will replace , False will copy,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Set oNewTitleBlockDef = oSourceTitleBlockDef.CopyTo(odrawdoc,&lt;FONT color="#ff0000"&gt;True&lt;/FONT&gt;)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Have you check this free&amp;nbsp;addin.&lt;/P&gt;&lt;P&gt;Automatic update Drawing Resources&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A target="_blank" href="http://www.mcadforums.com/forums/viewtopic.php?f=34&amp;amp;t=8018"&gt;http://www.mcadforums.com/forums/viewtopic.php?f=34&amp;amp;t=8018&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;Rene J&lt;/P&gt;</description>
      <pubDate>Wed, 08 May 2013 05:46:15 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/vba-replace-title-block-definitions-in-drawing-from-template/m-p/3912585#M130950</guid>
      <dc:creator>Rene-J</dc:creator>
      <dc:date>2013-05-08T05:46:15Z</dc:date>
    </item>
    <item>
      <title>Re: VBA Replace title block definitions in drawing from template file</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/vba-replace-title-block-definitions-in-drawing-from-template/m-p/3913485#M130951</link>
      <description>&lt;P&gt;Thanks for the tip. I was able to switch back to my original code with that argument added and it works great. Well other than the occasional error adding the title block back in on multisheet drawings. Only seems to happen on a few when I don't activate sheets. Might just have to have it activate all sheets, it's not that much slower even on larger assembly drawings. Or after writing all of that I went and added an on error, which activates the current sheet on an error. Which is doing the trick nicely.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;About the addin, I see two reasons I probably won't start using them in general. From what I read this addin automatically updates drawings when opened, definitely don't want to do that since certain things have edited title blocks. For addins in general it seems you have to install them, which I figure the others in my department wouldn't do. Most of them won't even manually replace a title block, lol.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Final code (for now)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Sub Update_TitleBlock()
    On Error GoTo ErrHandler:
    
    Dim odrawdoc As DrawingDocument
    Set odrawdoc = ThisApplication.ActiveDocument

    If (odrawdoc.DocumentType &amp;lt;&amp;gt; kDrawingDocumentObject) Then Exit Sub
    
    Dim oTemplate As DrawingDocument
    Dim oSourceTitleBlockDef As TitleBlockDefinition
    Dim oNewTitleBlockDef As TitleBlockDefinition
    Dim oSheet As Sheet
    Dim titlename As String
    
    Set oSheet = odrawdoc.ActiveSheet
    
    If (oSheet.TitleBlock.name = "ASSY") Then
        titlename = "ASSY"
        fname = "D_ASSY.idw"
    ElseIf (oSheet.TitleBlock.name = "TOLERANCE") Then
        titlename = "TOLERANCE"
        fname = "D_DET.idw"
    Else:
        MsgBox "This drawing has an unknown title block"
        Exit Sub
    End If
    
    Set oTemplate = ThisApplication.Documents.Open(ThisApplication.FileOptions.TemplatesPath &amp;amp; fname, False)
    Set oSourceTitleBlockDef = oTemplate.ActiveSheet.TitleBlock.Definition
    Set oNewTitleBlockDef = oSourceTitleBlockDef.CopyTo(odrawdoc, True)
    
    ' Iterate through the sheets.
    For Each oSheet In odrawdoc.Sheets
        'oSheet.Activate if error occurs
        oSheet.TitleBlock.Delete
        Call oSheet.AddTitleBlock(oNewTitleBlockDef)
    Next
    oTemplate.Close
    
    Exit Sub
ErrHandler:
    oSheet.Activate
    Resume
End Sub&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 08 May 2013 11:49:50 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/vba-replace-title-block-definitions-in-drawing-from-template/m-p/3913485#M130951</guid>
      <dc:creator>pball</dc:creator>
      <dc:date>2013-05-08T11:49:50Z</dc:date>
    </item>
    <item>
      <title>Re: VBA Replace title block definitions in drawing from template file</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/vba-replace-title-block-definitions-in-drawing-from-template/m-p/3913526#M130952</link>
      <description>I would recommend you move the on error statement to just before the for each sheet loop. This will make debugging easier if you have a problem with the code somewhere before that.</description>
      <pubDate>Wed, 08 May 2013 12:26:49 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/vba-replace-title-block-definitions-in-drawing-from-template/m-p/3913526#M130952</guid>
      <dc:creator>mrattray</dc:creator>
      <dc:date>2013-05-08T12:26:49Z</dc:date>
    </item>
    <item>
      <title>Re: VBA Replace title block definitions in drawing from template file</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/vba-replace-title-block-definitions-in-drawing-from-template/m-p/3913536#M130953</link>
      <description>&lt;P&gt;Thanks. Haven't used on error much so doing that completely slipped my mind.&lt;/P&gt;</description>
      <pubDate>Wed, 08 May 2013 12:38:35 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/vba-replace-title-block-definitions-in-drawing-from-template/m-p/3913536#M130953</guid>
      <dc:creator>pball</dc:creator>
      <dc:date>2013-05-08T12:38:35Z</dc:date>
    </item>
    <item>
      <title>Re: VBA Replace title block definitions in drawing from template file</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/vba-replace-title-block-definitions-in-drawing-from-template/m-p/5643725#M130954</link>
      <description>&lt;P&gt;I would like to know why I have an error when I am at line:&lt;/P&gt;&lt;PRE&gt;Call oSheet.AddTitleBlock(oNewTitleBlockDef)&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;It returns me an Run-time error '5' all the time. The rest goes very well. Thanks for your help&lt;/P&gt;</description>
      <pubDate>Wed, 20 May 2015 15:54:11 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/vba-replace-title-block-definitions-in-drawing-from-template/m-p/5643725#M130954</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2015-05-20T15:54:11Z</dc:date>
    </item>
    <item>
      <title>Re: VBA Replace title block definitions in drawing from template file</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/vba-replace-title-block-definitions-in-drawing-from-template/m-p/9354475#M130955</link>
      <description>&lt;P&gt;I realize this is an old thread, but happen to be working on something similar and someone else may find it useful.&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;As &lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/84502"&gt;@Rene-J&lt;/a&gt; was kind enough to point out, there is a replace function that can be used instead of delete.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;EM&gt;Set oNewTitleBlockDef = oSourceTitleBlockDef.CopyTo(odrawdoc,&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;True&lt;/FONT&gt;&lt;/STRONG&gt;)&lt;/EM&gt;&lt;/PRE&gt;&lt;P&gt;If this is used; it is the same as if it's done through the UI. Copying the drawing resources from one drawing to another and choosing the option to replace (assuming they have the same name). The TB definition replaces all occurrences on all sheets and will keep the individual prompted text property values (assuming the prompted text properties have the same name).&lt;BR /&gt;&lt;BR /&gt;From the code posted earlier, I was getting the same "Run-time error 5". I think it was because it was trying to replace an identical instance of the TB on subsequent sheets (but that's just my best guess).&lt;BR /&gt;&lt;BR /&gt;I removed the for each loop and oSheet.Activate and everything is working perfectly.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;    ...End If&lt;BR /&gt;&lt;BR /&gt;    Set oTemplate = ThisApplication.Documents.Open(ThisApplication.FileOptions.TemplatesPath &amp;amp; fname, False) 'open visible = false&lt;BR /&gt;    Set oSourceTitleBlockDef = oTemplate.ActiveSheet.TitleBlock.Definition&lt;BR /&gt;    Set oNewTitleBlockDef = oSourceTitleBlockDef.CopyTo(odrawdoc, True) 'True will replace titleblock at destination with TB from source&lt;BR /&gt;&lt;BR /&gt;    oTemplate.Close&lt;BR /&gt;&lt;BR /&gt;End Sub&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 03 Mar 2020 06:26:58 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/vba-replace-title-block-definitions-in-drawing-from-template/m-p/9354475#M130955</guid>
      <dc:creator>tmuel</dc:creator>
      <dc:date>2020-03-03T06:26:58Z</dc:date>
    </item>
  </channel>
</rss>

