Link to home
Start Free TrialLog in
Avatar of Phil Chapman
Phil ChapmanFlag for United States of America

asked on

Read EXCEL File

Reading EXCEL Files
Occasionally I receive a file that was created in some software packages where I can’t see either the first or last column using the code below.

If I open the file in excel and save the file then the missing column is displayed.

I’ve tried referencing
Reference Microsoft ActiveX Data Obect 2.6 Libary
Reference Microsoft ActiveX Data Obect 2.7 Library
Reference Microsoft ActiveX Data Obect 2.8 Library
With no difference


The attachmet is the Sub that reades the Excel File and writes the contents to a Tab Delimited File.

I suspect the problem may be in open syntex ( see below )

Dim oConn As ADODB.Connection
Set oConn = New ADODB.Connection
oConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
           "Data Source=" & sExcelFileName & ";" & _
           "Extended Properties=""Excel 8.0;HDR=YES;"""

Any help will be appreciated.
Thanks,
Phil
ASKER CERTIFIED SOLUTION
Avatar of markdmac
markdmac
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Phil Chapman

ASKER

Great Answer

I'm opening another quest how to save the file as a Tab Delimited File instead of a Excel file

Question:
Save Excel File as a Tab Delimited File
Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Open("C:\Temp\MyFile.xls")
strOutputFileName = "C:\TEMP\MyFile.txt"
xlApp.ActiveWorkbook.SaveAs strOutputFileName,-4158,false 'this saves as tabdelimited file
xlApp.Quit
Markdmac,
It working ok but it's asking if I won't to save the chagnes how can I suspress this?
Markadmac,
I found the answer

Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Open(InputFileName)
xlApp.ActiveWorkbook.SaveAs OutPutFileName, -4158, False 'this saves as tabdelimited file
xlApp.Application.DisplayAlerts = False
xlApp.Quit
Glad you were able to find the answer for the prompt.
Regards,
Mark