
Accessing an Excel file without opening Excel
Hi Kerri,
You always need to start Excel, but if you want to you can make sure
that the user doesn't see it like this:
Dim X As Object
Set X=CreateObject(,"Excel.Application")
X.Visible=False
About adding the reference:
The wqay you have coded (CreateObject) you don't need this reference.
Personally (I work a lot with Office 97 and VB 6) I never use these
references, but I always work with createObject.
The can prevend the error you get by using this code (I think):
Dim X As Object
Dim Ws as Object
Set X=CreateObject(,"Excel.Application")
X.Visible=False
set WS=X.Workbookes("Filename").Sheets("SheetName")
This should work fine in Office 97. I'm not sure about the
Object-structure of Office 7.0.
Gerard
Quote:
>I'm trying to access an Excel 7.0 spreadsheet through my app in VB 6.0
>without actually opening Excel. (I've added the Microsoft Excel 5.0
>Object Library in my Project-References section...I'm assuming that's
>the right library to add since the only other library for Excel in VB is
>Office 97 - which my users don't use.) First of all, is this possible?
>Second of all, I tried this code out and get an error at the line where
>I reference the Workbook object saying "Workbooks method of Application
>class failed"...
>Dim objList As Object
>Dim wkbList As Worksheet
>Dim nRows As Integer
>Dim arrListValues() As String
>Dim i As Integer
>Set objList = CreateObject("Excel.Application")
>Set wkbList = objList.Workbooks(txtListFile).Sheets("Sheet1")
>nRows = wkbList.Rows.Count
>ReDim Preserve arrListValues(1 To nRows)
>For i = 1 To nRows
> ' Fill the array with the values from column A of the worksheet.
> arrListValues(i) = wkbList.Range("A" & i + 1).Value
>Next i
>Sent via Deja.com http://www.deja.com/
>Before you buy.