Solved

Read EXCEL File

Posted on 2012-03-22
6
240 Views
Last Modified: 2012-03-23
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
0
Comment
Question by:PhilChapmanJr
  • 3
  • 3
6 Comments
 
LVL 15

Accepted Solution

by:
markdmac earned 500 total points
ID: 37755800
How about just opening in Excel and saving the file via VB?

Public Sub saveSheets()
  Dim xlApp As Object
  Dim xlBook As Object
  Dim xlSheet As Object
  Dim strOutputFileName

  Set xlApp = CreateObject("Excel.Application")
  Set xlBook = xlApp.Workbooks.Open("E:\Temp\MyFile.xls")
  For Each xlSheet In xlBook.Worksheets
    strOutputFileName = "C:\TEMP\MyFile2.xls"
    xlSheet.SaveAs strOutputFileName
  Next
  xlApp.Quit
End Sub
0
 
LVL 2

Author Closing Comment

by:PhilChapmanJr
ID: 37758016
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
0
 
LVL 15

Expert Comment

by:markdmac
ID: 37758163
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
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 2

Author Comment

by:PhilChapmanJr
ID: 37758318
Markdmac,
It working ok but it's asking if I won't to save the chagnes how can I suspress this?
0
 
LVL 2

Author Comment

by:PhilChapmanJr
ID: 37758728
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
0
 
LVL 15

Expert Comment

by:markdmac
ID: 37759462
Glad you were able to find the answer for the prompt.
Regards,
Mark
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

912 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now