<?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: Excel VBA Macro and Changing AutoCAD Versions in VBA Forum</title>
    <link>https://forums.autodesk.com/t5/vba-forum/excel-vba-macro-and-changing-autocad-versions/m-p/9341086#M4879</link>
    <description>&lt;P&gt;There are two ways to handle this. The first you mentioned, is to programatically handle project references. You do this by referencing &lt;FONT color="#3366FF"&gt;Microsoft Visual Basic for Applications Extensibility 5.3&lt;/FONT&gt; tlb. Then you can reference/unreference tlb's. I created this sub for use with AutoCAD. You would have to change it for Excel.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt; Public Function SetReferenceByGUID(strGUID As String, maj As Long, min As Long) As VBIDE.Reference

     'Returns a Reference object if successful in setting a reference in the current dvb,
     'given the GUID of a tlb, olb, dll. Using a GUID avoids having to test
     'for a valid filepath.
     On Error GoTo ErrorHandler
     Dim objVB As VBE
     Dim objRef As VBIDE.Reference
     Dim objRefs As VBIDE.References
     Dim strPath As String

     Set objVB = Application.VBE
     Set objRef = objVB.ActiveVBProject.References.AddFromGuid(strGUID, maj, min)
     Set SetReferenceByGUID = objRef
     GoTo Finish:
ErrorHandler:
     If Err.Number = 32813 Then
         'reference was already set, just return the reference
         Set objRefs = objVB.ActiveVBProject.References
         For Each objRef In objRefs
             If objRef.GUID = strGUID Then
                 Set SetReferenceByGUID = objRef
             End If
         Next objRef
     Else
         Set SetReferenceByGUID = Nothing
     End If
Finish:
     Set objVB = Nothing
     Set objRef = Nothing
 End Function
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The second way is to use Late Binding. You do this by dimensioning variables as Object rather than class specific. This makes development harder though, since you don't get Intellisense help when specifying methods/properties. To get around this, first get the project working and tested using regular binding, dimensioning as specific classes. Then after testing, set everything to Object. When I say everything, I mean only the AutoCAD variables.&lt;/P&gt;</description>
    <pubDate>Tue, 25 Feb 2020 20:40:46 GMT</pubDate>
    <dc:creator>Ed__Jobe</dc:creator>
    <dc:date>2020-02-25T20:40:46Z</dc:date>
    <item>
      <title>Excel VBA Macro and Changing AutoCAD Versions</title>
      <link>https://forums.autodesk.com/t5/vba-forum/excel-vba-macro-and-changing-autocad-versions/m-p/9341057#M4878</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've got a question about reference libraries that I was hoping someone could help me out with. We have an excel template that we use for product design that I've written a VBA macro for that completes an AutoCAD drawing file with the design parameters from Excel. Everything works fine as written, used with the AutoCAD version (2016) it was written with, but we've updated our AutoCAD software version and the macro won't work properly without reloading the correct reference libraries. The macro uses the AXDBLib (axdb20enu.tlb) and AutoCAD 2016 Type Library (acax20enu.tlb) to generate the drawing file.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, this is a file used by multiple people in the company, which means that changing the references for a newer version complicates things for someone who hasn't been updated from the old version yet. Also, with the update schedule they've released, this issue will continue to come up as newer versions are introduced, older versions of the Excel file would have the same issue if used in the future, etc.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a way to structure the macro to load (and potentially unload) the AutoCAD reference libraries mentioned above based on the software version of the person trying to run the macro through Excel? That way, people using multiple different versions of AutoCAD can each successfully use the same template file at the same time, with the same macro still working if needed to generate the file at a later date and time. Thanks!&lt;/P&gt;</description>
      <pubDate>Tue, 25 Feb 2020 20:20:42 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/excel-vba-macro-and-changing-autocad-versions/m-p/9341057#M4878</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-02-25T20:20:42Z</dc:date>
    </item>
    <item>
      <title>Re: Excel VBA Macro and Changing AutoCAD Versions</title>
      <link>https://forums.autodesk.com/t5/vba-forum/excel-vba-macro-and-changing-autocad-versions/m-p/9341086#M4879</link>
      <description>&lt;P&gt;There are two ways to handle this. The first you mentioned, is to programatically handle project references. You do this by referencing &lt;FONT color="#3366FF"&gt;Microsoft Visual Basic for Applications Extensibility 5.3&lt;/FONT&gt; tlb. Then you can reference/unreference tlb's. I created this sub for use with AutoCAD. You would have to change it for Excel.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt; Public Function SetReferenceByGUID(strGUID As String, maj As Long, min As Long) As VBIDE.Reference

     'Returns a Reference object if successful in setting a reference in the current dvb,
     'given the GUID of a tlb, olb, dll. Using a GUID avoids having to test
     'for a valid filepath.
     On Error GoTo ErrorHandler
     Dim objVB As VBE
     Dim objRef As VBIDE.Reference
     Dim objRefs As VBIDE.References
     Dim strPath As String

     Set objVB = Application.VBE
     Set objRef = objVB.ActiveVBProject.References.AddFromGuid(strGUID, maj, min)
     Set SetReferenceByGUID = objRef
     GoTo Finish:
ErrorHandler:
     If Err.Number = 32813 Then
         'reference was already set, just return the reference
         Set objRefs = objVB.ActiveVBProject.References
         For Each objRef In objRefs
             If objRef.GUID = strGUID Then
                 Set SetReferenceByGUID = objRef
             End If
         Next objRef
     Else
         Set SetReferenceByGUID = Nothing
     End If
Finish:
     Set objVB = Nothing
     Set objRef = Nothing
 End Function
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The second way is to use Late Binding. You do this by dimensioning variables as Object rather than class specific. This makes development harder though, since you don't get Intellisense help when specifying methods/properties. To get around this, first get the project working and tested using regular binding, dimensioning as specific classes. Then after testing, set everything to Object. When I say everything, I mean only the AutoCAD variables.&lt;/P&gt;</description>
      <pubDate>Tue, 25 Feb 2020 20:40:46 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/excel-vba-macro-and-changing-autocad-versions/m-p/9341086#M4879</guid>
      <dc:creator>Ed__Jobe</dc:creator>
      <dc:date>2020-02-25T20:40:46Z</dc:date>
    </item>
    <item>
      <title>Re: Excel VBA Macro and Changing AutoCAD Versions</title>
      <link>https://forums.autodesk.com/t5/vba-forum/excel-vba-macro-and-changing-autocad-versions/m-p/9356212#M4880</link>
      <description>&lt;P&gt;Hi Ed,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The code you provided for setting the reference by GUID works as long as the GUID is known. Is there a way to determine the GUID from the Autocad version installed for the axdbXXenu.tlb and acaxXXenu.tlb libraries? That way, if the user needs to load the acax20enu.tlb for 2016, the acax22enu.tlb for 2018, etc., the code is able to verify the correct GUID instead of requiring that as an input.&lt;/P&gt;</description>
      <pubDate>Tue, 03 Mar 2020 19:27:43 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/excel-vba-macro-and-changing-autocad-versions/m-p/9356212#M4880</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-03-03T19:27:43Z</dc:date>
    </item>
    <item>
      <title>Re: Excel VBA Macro and Changing AutoCAD Versions</title>
      <link>https://forums.autodesk.com/t5/vba-forum/excel-vba-macro-and-changing-autocad-versions/m-p/9358322#M4881</link>
      <description>&lt;P&gt;Perhaps this function is better suited to your needs.&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;Public Function SetReferenceByFile(FilePath As String, Optional DisplayErrors As Boolean) As VBIDE.Reference
    'returns True if successful in setting a reference in the current dvb,
    'given the FilePath of a tlb, olb, dll. The DisplayErrors option determines
    'whether or not an error message will be displayed upon erroring.
    On Error GoTo ErrorHandler
    Dim objVB As Object  'VBE
    Dim objRef As VBIDE.Reference
    Dim objRefs As VBIDE.References
    Dim strPath As String
    
    Set objVB = AcadApplication.VBE
    Set objRef = objVB.ActiveVBProject.References.AddFromFile(FilePath)
    SetReferenceByFile = True
    GoTo Finish:
ErrorHandler:
    If Err.Number = 32813 Then
        'reference was already set, just return the reference
         Set objRefs = objVB.ActiveVBProject.References
         For Each objRef In objRefs
             If objRef.FullPath = FilePath Then
                 Set SetReferenceByFile = objRef
             End If
         Next objRef
    Else
        If DisplayErrors = True Then
            MsgBox Err.Number &amp;amp; ", " &amp;amp; Err.Description, vbExclamation, "SetReferenceByFile."
        Else
        
        End If
        Set SetReferenceByFile = Nothing
    End If
Finish:
    Set objVB = Nothing
    Set objRef = Nothing
End Function&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The next problem is deciding how to detect which version is installed. Is it possible that a user can have more than one version of acad installed?&lt;/P&gt;</description>
      <pubDate>Wed, 04 Mar 2020 16:16:44 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/excel-vba-macro-and-changing-autocad-versions/m-p/9358322#M4881</guid>
      <dc:creator>Ed__Jobe</dc:creator>
      <dc:date>2020-03-04T16:16:44Z</dc:date>
    </item>
  </channel>
</rss>

