Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default ADO - Excel - External table is not in the expected format


I copied the data into a new file, and then it works fine.
Im using some others files that work fine.
The error ocurr just when the program tries to open the connection to
the file.

If somebody can give me a hint?

This is the code that i used to open the excel file.

strExcelConnectionString =
"Provider=Microsoft.Jet.OLEDB.4.0;data source=" & strFileName &
";Extended Properties=""Excel 8.0;HDR=No;IMEX=1"""

cn.ConnectionString = strExcelConnectionString
cn.Open

Thanks!!!



*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default ADO - Excel - External table is not in the expected format

Adriuana,

What is cn in this code?

This works fine for me

Dim oRS As Object
Dim sConnect As String
Dim sSQL As String
Dim sFile As String
Dim oOrig As Worksheet
Dim osh As Worksheet
Dim oCell As Range
Dim aryData

sFile = "C:\myTest\Volker1.xls"


' Query based on the worksheet name.
sSQL = "SELECT * FROM [Sheet1$]"

Set oRS = CreateObject("ADODB.Recordset")
oRS.Open sSQL, sConnect, 0, 1, 1

If Not oRS.EOF Then
aryData = oRS.getrows()
Else
MsgBox "No records returned.", vbCritical
End If

MsgBox "Cell A2 contains " & aryData(0, 0)
MsgBox "Cell D4 contains " & aryData(3, 2)

' Clean up our Recordset object.
oRS.Close
Set oRS = Nothing

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Adriana Camargo" wrote in message
...

I copied the data into a new file, and then it works fine.
Im using some others files that work fine.
The error ocurr just when the program tries to open the connection to
the file.

If somebody can give me a hint?

This is the code that i used to open the excel file.

strExcelConnectionString =
"Provider=Microsoft.Jet.OLEDB.4.0;data source=" & strFileName &
";Extended Properties=""Excel 8.0;HDR=No;IMEX=1"""

cn.ConnectionString = strExcelConnectionString
cn.Open

Thanks!!!



*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 459
Default ADO - Excel - External table is not in the expected format

Adriana Camargo wrote ...
I copied the data into a new file, and then it works fine.
Im using some others files that work fine.
The error ocurr just when the program tries to open the connection to
the file.

If somebody can give me a hint?

This is the code that i used to open the excel file.

strExcelConnectionString =
"Provider=Microsoft.Jet.OLEDB.4.0;data source=" & strFileName &
";Extended Properties=""Excel 8.0;HDR=No;IMEX=1"""

cn.ConnectionString = strExcelConnectionString
cn.Open

Thanks!!!


You code worked for me as posted, but you may want to try without the
IMEX=1 (do you need it?) in the connection string and check whether
HDR=No (i.e. no column/field headers) is correct:

Dim cn As ADODB.Connection
Set cn = New ADODB.Connection
Dim strExcelConnectionString As String
Dim strFileName As String
strFileName = "C:\Tempo\db.xls"
strExcelConnectionString = "" & _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"data source=" & strFileName & ";" & _
"Extended Properties=""Excel 8.0;HDR=Yes"""
cn.ConnectionString = strExcelConnectionString
cn.Open ' << no error for me!

--
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default ADO - Excel - External table is not in the expected format

Yeah, it works fine with some files, but with others, it fails. The
problem is that i have to work with many files that have same structure,
but different information. So, i have no control on the information in
the file.

I have to use HDR=NO because the files dont have a header or column
name, so if use HDR=YES, it will skip a row.

I have to use IMEX=1, because if i dont use it, the code doesnt read
some values in the cells, and them will be set as NULL. I found in some
microsoft article, that this happens when in the same column i have
different types of data (numbers, and characters)

http://support.microsoft.com/default...b;EN-US;194124

So i havent found a solution. :(
Any suggestions?

Thanks for your help!!!








*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
External table is not in the expected format. Amy E. Baggott Excel Discussion (Misc queries) 0 May 8th 09 04:26 PM
DATE FORMAT IN PIVOT TABLE FROM EXTERNAL DATA SOURCE uncreative Excel Discussion (Misc queries) 2 February 23rd 07 04:51 PM
Pivot Table Wizard Error (Expected 52) Guest Excel Discussion (Misc queries) 0 April 28th 06 10:10 PM
LOOKUP function not returning expected value - Using vector_lookup format JerichoForce Excel Worksheet Functions 2 April 18th 06 10:45 AM
external database to view in EXCEL format mangyan Excel Discussion (Misc queries) 0 October 28th 05 03:56 PM


All times are GMT +1. The time now is 12:39 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"