<?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: Code that works with different versions of Excel in VBA Forum</title>
    <link>https://forums.autodesk.com/t5/vba-forum/code-that-works-with-different-versions-of-excel/m-p/1863953#M28272</link>
    <description>All I can say is "Try it..." &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; If it works, then fine, but I think that in &lt;BR /&gt;
order to use the explict reference of Excel.Workbook you would need to have &lt;BR /&gt;
the reference.....which will lead back to the "user defined type not &lt;BR /&gt;
defined" error&lt;BR /&gt;
&lt;BR /&gt;
&lt;HUTCH&gt; wrote in message news:5453303@discussion.autodesk.com...&lt;BR /&gt;
Thanks you so much... this wil get me a leg up...&lt;BR /&gt;
I follow what you are doing.&lt;BR /&gt;
&lt;BR /&gt;
One question though...&lt;BR /&gt;
With this late binding method (without the reference set)...&lt;BR /&gt;
is it necessary to do:&lt;BR /&gt;
Dim oWb As Object&lt;BR /&gt;
Dim oWs As Object&lt;BR /&gt;
&lt;BR /&gt;
Why can't the following be used?&lt;BR /&gt;
&lt;BR /&gt;
Dim oWb As Excel.Workbook&lt;BR /&gt;
Dim oWs As Excel.Worksheet&lt;/HUTCH&gt;</description>
    <pubDate>Tue, 16 Jan 2007 20:23:14 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2007-01-16T20:23:14Z</dc:date>
    <item>
      <title>Code that works with different versions of Excel</title>
      <link>https://forums.autodesk.com/t5/vba-forum/code-that-works-with-different-versions-of-excel/m-p/1863950#M28269</link>
      <description>I made some lisp code to harvest the excel location on each workstation... &lt;BR /&gt;
&lt;BR /&gt;
We have some machines that the Excel file is Excel9.olb and others that are Offic10/Excel.exe&lt;BR /&gt;
&lt;BR /&gt;
C:/Program Files/Microsoft Office/Office/Excel9.olb&lt;BR /&gt;
C:/Program Files/Microsoft Office/Office10/Excel.exe&lt;BR /&gt;
&lt;BR /&gt;
On my machine where I am developing my application the reference is set to Microsoft Excel 10.0 Object Library.&lt;BR /&gt;
&lt;BR /&gt;
How can I develop my app so it will work for either version?&lt;BR /&gt;
…  we have several out-of-house resources that we require to use our program code… what if they have Excel version other than these?</description>
      <pubDate>Tue, 16 Jan 2007 17:26:22 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/code-that-works-with-different-versions-of-excel/m-p/1863950#M28269</guid>
      <dc:creator>mdhutchinson</dc:creator>
      <dc:date>2007-01-16T17:26:22Z</dc:date>
    </item>
    <item>
      <title>Re: Code that works with different versions of Excel</title>
      <link>https://forums.autodesk.com/t5/vba-forum/code-that-works-with-different-versions-of-excel/m-p/1863951#M28270</link>
      <description>Here's what I use.....note that for this to work you must remove the &lt;BR /&gt;
Reference to Excel. I found it's easiest to code WITH the reference, that &lt;BR /&gt;
way you have the use of Intellisense, and once it's working go back and &lt;BR /&gt;
change it to be late binding as I show here:&lt;BR /&gt;
&lt;BR /&gt;
'' Modified 10/8/03 to remove early binding and&lt;BR /&gt;
'' include late binding. Now should work with&lt;BR /&gt;
'' any version Excel&lt;BR /&gt;
&lt;BR /&gt;
Option Explicit&lt;BR /&gt;
Function IsExcelRunning() As Boolean&lt;BR /&gt;
     Dim objXL As Object&lt;BR /&gt;
     On Error Resume Next&lt;BR /&gt;
     Set objXL = GetObject(, "Excel.Application")&lt;BR /&gt;
     IsExcelRunning = (Err.Number = 0)&lt;BR /&gt;
     Set objXL = Nothing&lt;BR /&gt;
     Err.Clear&lt;BR /&gt;
   End Function&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
'Changed the way Excel is loaded per suggestion by&lt;BR /&gt;
'Randall Rath - http://www.vbdesign.net/&lt;BR /&gt;
'which also added the "Function IsExcelRunning", found above&lt;BR /&gt;
&lt;BR /&gt;
Public Sub AddData(DwgFullName As String, vData As Variant)&lt;BR /&gt;
Dim sXlFilNam As String&lt;BR /&gt;
&lt;BR /&gt;
  sXlFilNam = Left(DwgFullName, Len(DwgFullName) - 3) &amp;amp; "xls"&lt;BR /&gt;
'***Begin code from Randall Rath******&lt;BR /&gt;
  Dim oXL As Object&lt;BR /&gt;
  Dim blnXLRunning As Boolean&lt;BR /&gt;
     blnXLRunning = IsExcelRunning()&lt;BR /&gt;
     If blnXLRunning Then&lt;BR /&gt;
       Set oXL = GetObject(, "Excel.Application")&lt;BR /&gt;
     Else&lt;BR /&gt;
       Set oXL = CreateObject("Excel.Application")&lt;BR /&gt;
       oXL.Visible = False&lt;BR /&gt;
       oXL.UserControl = False&lt;BR /&gt;
     End If&lt;BR /&gt;
'***End code from Randall Rath******&lt;BR /&gt;
  Dim oWb As Object&lt;BR /&gt;
  Dim oWs As Object&lt;BR /&gt;
&lt;BR /&gt;
  Set oWb = oXL.Workbooks.Open(sXlFilNam)&lt;BR /&gt;
&lt;BR /&gt;
  Set oWs = oWb.Worksheets("MySheet")&lt;BR /&gt;
  If oWs Is Nothing Then&lt;BR /&gt;
    MsgBox "The Excel file " &amp;amp; sXlFilNam &amp;amp; " is an old file, please delete &lt;BR /&gt;
and try again."&lt;BR /&gt;
    GoTo exithere&lt;BR /&gt;
  End If&lt;BR /&gt;
''''Your code here&lt;BR /&gt;
exithere:&lt;BR /&gt;
  Set oWs = Nothing&lt;BR /&gt;
&lt;BR /&gt;
  oWb.Save: oWb.Close&lt;BR /&gt;
  Set oWb = Nothing&lt;BR /&gt;
&lt;BR /&gt;
  oXL.Quit&lt;BR /&gt;
  Set oXL = Nothing&lt;BR /&gt;
&lt;BR /&gt;
End Sub&lt;BR /&gt;
&lt;BR /&gt;
&lt;HUTCH&gt; wrote in message news:5453103@discussion.autodesk.com...&lt;BR /&gt;
I made some lisp code to harvest the excel location on each workstation...&lt;BR /&gt;
&lt;BR /&gt;
We have some machines that the Excel file is Excel9.olb and others that are &lt;BR /&gt;
Offic10/Excel.exe&lt;BR /&gt;
&lt;BR /&gt;
C:/Program Files/Microsoft Office/Office/Excel9.olb&lt;BR /&gt;
C:/Program Files/Microsoft Office/Office10/Excel.exe&lt;BR /&gt;
&lt;BR /&gt;
On my machine where I am developing my application the reference is set to &lt;BR /&gt;
Microsoft Excel 10.0 Object Library.&lt;BR /&gt;
&lt;BR /&gt;
How can I develop my app so it will work for either version?&lt;BR /&gt;
.  we have several out-of-house resources that we require to use our program &lt;BR /&gt;
code. what if they have Excel version other than these?&lt;/HUTCH&gt;</description>
      <pubDate>Tue, 16 Jan 2007 18:17:03 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/code-that-works-with-different-versions-of-excel/m-p/1863951#M28270</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2007-01-16T18:17:03Z</dc:date>
    </item>
    <item>
      <title>Re: Code that works with different versions of Excel</title>
      <link>https://forums.autodesk.com/t5/vba-forum/code-that-works-with-different-versions-of-excel/m-p/1863952#M28271</link>
      <description>Thanks you so much... this wil get me a leg up...&lt;BR /&gt;
I follow what you are doing.&lt;BR /&gt;
&lt;BR /&gt;
One question though...&lt;BR /&gt;
With this late binding method (without the reference set)...&lt;BR /&gt;
is it necessary to do:&lt;BR /&gt;
Dim oWb As Object&lt;BR /&gt;
Dim oWs As Object&lt;BR /&gt;
&lt;BR /&gt;
Why can't the following be used?&lt;BR /&gt;
&lt;BR /&gt;
Dim oWb As Excel.Workbook&lt;BR /&gt;
Dim oWs As Excel.Worksheet</description>
      <pubDate>Tue, 16 Jan 2007 19:39:40 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/code-that-works-with-different-versions-of-excel/m-p/1863952#M28271</guid>
      <dc:creator>mdhutchinson</dc:creator>
      <dc:date>2007-01-16T19:39:40Z</dc:date>
    </item>
    <item>
      <title>Re: Code that works with different versions of Excel</title>
      <link>https://forums.autodesk.com/t5/vba-forum/code-that-works-with-different-versions-of-excel/m-p/1863953#M28272</link>
      <description>All I can say is "Try it..." &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; If it works, then fine, but I think that in &lt;BR /&gt;
order to use the explict reference of Excel.Workbook you would need to have &lt;BR /&gt;
the reference.....which will lead back to the "user defined type not &lt;BR /&gt;
defined" error&lt;BR /&gt;
&lt;BR /&gt;
&lt;HUTCH&gt; wrote in message news:5453303@discussion.autodesk.com...&lt;BR /&gt;
Thanks you so much... this wil get me a leg up...&lt;BR /&gt;
I follow what you are doing.&lt;BR /&gt;
&lt;BR /&gt;
One question though...&lt;BR /&gt;
With this late binding method (without the reference set)...&lt;BR /&gt;
is it necessary to do:&lt;BR /&gt;
Dim oWb As Object&lt;BR /&gt;
Dim oWs As Object&lt;BR /&gt;
&lt;BR /&gt;
Why can't the following be used?&lt;BR /&gt;
&lt;BR /&gt;
Dim oWb As Excel.Workbook&lt;BR /&gt;
Dim oWs As Excel.Worksheet&lt;/HUTCH&gt;</description>
      <pubDate>Tue, 16 Jan 2007 20:23:14 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/code-that-works-with-different-versions-of-excel/m-p/1863953#M28272</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2007-01-16T20:23:14Z</dc:date>
    </item>
  </channel>
</rss>

