Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Read EXCEL File

Posted on 2012-03-22
6
Medium Priority
?
260 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 2000 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

916 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