Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Read EXCEL File

Posted on 2012-03-22
6
Medium Priority
?
257 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
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!

 
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

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…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…
Suggested Courses

664 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