<?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: Read Excel in VBA Forum</title>
    <link>https://forums.autodesk.com/t5/vba-forum/read-excel/m-p/1719765#M32266</link>
    <description>Hi Numpty,&lt;BR /&gt;
&lt;BR /&gt;
Sub CommandButton2_Click&lt;BR /&gt;
&lt;BR /&gt;
Set excelApp = GetObject(, "Excel.Appication")&lt;BR /&gt;
&lt;BR /&gt;
Application misspelled&lt;BR /&gt;
&lt;BR /&gt;
A Caddie.</description>
    <pubDate>Sat, 29 Jul 2006 16:48:51 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2006-07-29T16:48:51Z</dc:date>
    <item>
      <title>Read Excel</title>
      <link>https://forums.autodesk.com/t5/vba-forum/read-excel/m-p/1719764#M32265</link>
      <description>I have some code which should read an excel file. When I use the buttons my Listbox remains empty. I have loaded the Excel Object Library.  What is wrong?&lt;BR /&gt;
&lt;BR /&gt;
Private Sub CommandButton1_Click()&lt;BR /&gt;
Dim excelApp As Excel.Application&lt;BR /&gt;
Dim wbkObj As Workbook&lt;BR /&gt;
Dim shtObj As WorkSheet&lt;BR /&gt;
&lt;BR /&gt;
On Error Resume Next&lt;BR /&gt;
UserForm1.Hide&lt;BR /&gt;
Err.Clear&lt;BR /&gt;
Set excelApp = GetObject(, "Excel.Application")&lt;BR /&gt;
If Err &amp;lt;&amp;gt; 0 Then&lt;BR /&gt;
    Err.Clear&lt;BR /&gt;
    Set excelApp = CreateObject("Excel.Application")&lt;BR /&gt;
    If Err &amp;lt;&amp;gt; 0 Then&lt;BR /&gt;
        MsgBox "Cannot start Excel", vbExclamation&lt;BR /&gt;
        End&lt;BR /&gt;
    End If&lt;BR /&gt;
End If&lt;BR /&gt;
excelApp.Visible = True&lt;BR /&gt;
Set wbkObj = excelApp.Workbooks.Open("C:\Bob\Test.xls")&lt;BR /&gt;
Set shtObj = excelApp.Worksheets(1)&lt;BR /&gt;
UserForm1.Show&lt;BR /&gt;
End Sub&lt;BR /&gt;
&lt;BR /&gt;
Private Sub CommandButton2_Click()&lt;BR /&gt;
Dim excelApp As Excel.Application&lt;BR /&gt;
Dim wbkObj As Workbook&lt;BR /&gt;
Dim shtObj As WorkSheet&lt;BR /&gt;
Dim i As Integer&lt;BR /&gt;
Dim txt As String&lt;BR /&gt;
On Error Resume Next&lt;BR /&gt;
UserForm1.Hide&lt;BR /&gt;
Err.Clear&lt;BR /&gt;
Set excelApp = GetObject(, "Excel.Appication")&lt;BR /&gt;
excelApp.Visible = True&lt;BR /&gt;
Set shtObj = excelApp.Worksheets(1)&lt;BR /&gt;
ListBox1.Clear&lt;BR /&gt;
i = 1&lt;BR /&gt;
txt = shtObj.Cells(i, 2)&lt;BR /&gt;
Do While txt &amp;lt;&amp;gt; ""&lt;BR /&gt;
    ListBox1.AddItem txt&lt;BR /&gt;
    i = i + 1&lt;BR /&gt;
    txt = shtObj.Cells(i, 2)&lt;BR /&gt;
Loop&lt;BR /&gt;
UserForm1.Show&lt;BR /&gt;
&lt;BR /&gt;
End Sub</description>
      <pubDate>Sat, 29 Jul 2006 12:14:34 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/read-excel/m-p/1719764#M32265</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2006-07-29T12:14:34Z</dc:date>
    </item>
    <item>
      <title>Re: Read Excel</title>
      <link>https://forums.autodesk.com/t5/vba-forum/read-excel/m-p/1719765#M32266</link>
      <description>Hi Numpty,&lt;BR /&gt;
&lt;BR /&gt;
Sub CommandButton2_Click&lt;BR /&gt;
&lt;BR /&gt;
Set excelApp = GetObject(, "Excel.Appication")&lt;BR /&gt;
&lt;BR /&gt;
Application misspelled&lt;BR /&gt;
&lt;BR /&gt;
A Caddie.</description>
      <pubDate>Sat, 29 Jul 2006 16:48:51 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/read-excel/m-p/1719765#M32266</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2006-07-29T16:48:51Z</dc:date>
    </item>
    <item>
      <title>Re: Read Excel</title>
      <link>https://forums.autodesk.com/t5/vba-forum/read-excel/m-p/1719766#M32267</link>
      <description>And the reason you didn't see the error is the "On Error Resume Next" at the&lt;BR /&gt;
top of CommandButton2_Click().  It is the root of much evil.  Get rid of it,&lt;BR /&gt;
or at least reset the error handler immediately after.you've checked for the&lt;BR /&gt;
error.&lt;BR /&gt;
-- &lt;BR /&gt;
John Goodfellow&lt;BR /&gt;
irtfnm&lt;BR /&gt;
use john at goodfellowassoc dot com&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;NUMPTY&gt; wrote in message news:5252497@discussion.autodesk.com...&lt;BR /&gt;
I have some code which should read an excel file. When I use the buttons my&lt;BR /&gt;
Listbox remains empty. I have loaded the Excel Object Library.  What is&lt;BR /&gt;
wrong?&lt;BR /&gt;
&lt;BR /&gt;
Private Sub CommandButton1_Click()&lt;BR /&gt;
Dim excelApp As Excel.Application&lt;BR /&gt;
Dim wbkObj As Workbook&lt;BR /&gt;
Dim shtObj As WorkSheet&lt;BR /&gt;
&lt;BR /&gt;
On Error Resume Next&lt;BR /&gt;
UserForm1.Hide&lt;BR /&gt;
Err.Clear&lt;BR /&gt;
Set excelApp = GetObject(, "Excel.Application")&lt;BR /&gt;
If Err &amp;lt;&amp;gt; 0 Then&lt;BR /&gt;
    Err.Clear&lt;BR /&gt;
    Set excelApp = CreateObject("Excel.Application")&lt;BR /&gt;
    If Err &amp;lt;&amp;gt; 0 Then&lt;BR /&gt;
        MsgBox "Cannot start Excel", vbExclamation&lt;BR /&gt;
        End&lt;BR /&gt;
    End If&lt;BR /&gt;
End If&lt;BR /&gt;
excelApp.Visible = True&lt;BR /&gt;
Set wbkObj = excelApp.Workbooks.Open("C:\Bob\Test.xls")&lt;BR /&gt;
Set shtObj = excelApp.Worksheets(1)&lt;BR /&gt;
UserForm1.Show&lt;BR /&gt;
End Sub&lt;BR /&gt;
&lt;BR /&gt;
Private Sub CommandButton2_Click()&lt;BR /&gt;
Dim excelApp As Excel.Application&lt;BR /&gt;
Dim wbkObj As Workbook&lt;BR /&gt;
Dim shtObj As WorkSheet&lt;BR /&gt;
Dim i As Integer&lt;BR /&gt;
Dim txt As String&lt;BR /&gt;
On Error Resume Next&lt;BR /&gt;
UserForm1.Hide&lt;BR /&gt;
Err.Clear&lt;BR /&gt;
Set excelApp = GetObject(, "Excel.Appication")&lt;BR /&gt;
excelApp.Visible = True&lt;BR /&gt;
Set shtObj = excelApp.Worksheets(1)&lt;BR /&gt;
ListBox1.Clear&lt;BR /&gt;
i = 1&lt;BR /&gt;
txt = shtObj.Cells(i, 2)&lt;BR /&gt;
Do While txt &amp;lt;&amp;gt; ""&lt;BR /&gt;
    ListBox1.AddItem txt&lt;BR /&gt;
    i = i + 1&lt;BR /&gt;
    txt = shtObj.Cells(i, 2)&lt;BR /&gt;
Loop&lt;BR /&gt;
UserForm1.Show&lt;BR /&gt;
&lt;BR /&gt;
End Sub&lt;/NUMPTY&gt;</description>
      <pubDate>Mon, 31 Jul 2006 01:46:58 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/read-excel/m-p/1719766#M32267</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2006-07-31T01:46:58Z</dc:date>
    </item>
    <item>
      <title>Re: Read Excel</title>
      <link>https://forums.autodesk.com/t5/vba-forum/read-excel/m-p/1719767#M32268</link>
      <description>Thank you both. I would not have spotted the error AND you will probably save me future effort by being cautious with the "On Error Resume Next".  Your help is much appreciated.</description>
      <pubDate>Mon, 31 Jul 2006 07:38:52 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/read-excel/m-p/1719767#M32268</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2006-07-31T07:38:52Z</dc:date>
    </item>
    <item>
      <title>Re: Read Excel</title>
      <link>https://forums.autodesk.com/t5/vba-forum/read-excel/m-p/1719768#M32269</link>
      <description>Hi &lt;BR /&gt;
Reading values from Excel is always problematic.you can make use of databse, unless your application demands excel ..&lt;BR /&gt;
well i have found no mistake in your code but i dint understand why did u call excel in commnad button 1 click event by seeing your code i feel that u r just openning excel file in commandbuttton1 and agian openning excel and reading cell values in command button 2.Can you explain me wt r u doing in command button 1.</description>
      <pubDate>Mon, 31 Jul 2006 10:50:06 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/read-excel/m-p/1719768#M32269</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2006-07-31T10:50:06Z</dc:date>
    </item>
    <item>
      <title>Re: Read Excel</title>
      <link>https://forums.autodesk.com/t5/vba-forum/read-excel/m-p/1719769#M32270</link>
      <description>Hi Benny&lt;BR /&gt;
I am fairly new to VBA.  I tried to simplfy the read from excel function by splitting the program into two parts - one to open excel and one to read from excel (see attached). &lt;BR /&gt;
&lt;BR /&gt;
I really don't like the program opening excel and would much prefer it to just read the values.  I am think about using a txt file to hold the data.  I intend giving this program to many users who may have earlier copies of excel etc.  Your thoughts on this would be helpful.</description>
      <pubDate>Mon, 31 Jul 2006 11:01:50 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/read-excel/m-p/1719769#M32270</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2006-07-31T11:01:50Z</dc:date>
    </item>
    <item>
      <title>Re: Read Excel</title>
      <link>https://forums.autodesk.com/t5/vba-forum/read-excel/m-p/1719770#M32271</link>
      <description>Hi &lt;BR /&gt;
  try this code its working for me.&lt;BR /&gt;
&lt;BR /&gt;
 I had user form  and 1 command button and 1 listbox.&lt;BR /&gt;
I had prepared a excel document j.xls with names in column 2.&lt;BR /&gt;
&lt;BR /&gt;
Try out this,it should work....Gud luck&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Private Sub CommandButton1_Click()&lt;BR /&gt;
Dim Excel As Object&lt;BR /&gt;
    Dim excelSheet As Object&lt;BR /&gt;
    &lt;BR /&gt;
    Set Excel = CreateObject("Excel.Application")&lt;BR /&gt;
&lt;BR /&gt;
 Excel.Workbooks.Open FileName:="C:\j.xls", Editable:=True&lt;BR /&gt;
&lt;BR /&gt;
   Excel.Sheets("Sheet1").Select&lt;BR /&gt;
   Set excelSheet = Excel.ActiveWorkbook.Sheets("Sheet1")&lt;BR /&gt;
   Excel.Visible = True&lt;BR /&gt;
&lt;BR /&gt;
Dim i As Integer&lt;BR /&gt;
Dim txt As String&lt;BR /&gt;
ListBox1.Clear&lt;BR /&gt;
For i = 1 To 10&lt;BR /&gt;
txt = excelSheet.Cells(i, 2).Value&lt;BR /&gt;
If txt = "" Then Exit Sub&lt;BR /&gt;
ListBox1.AddItem txt&lt;BR /&gt;
Next i&lt;BR /&gt;
&lt;BR /&gt;
End Sub</description>
      <pubDate>Mon, 31 Jul 2006 11:17:52 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/read-excel/m-p/1719770#M32271</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2006-07-31T11:17:52Z</dc:date>
    </item>
  </channel>
</rss>

