473,513 Members | 2,429 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Unable to read columns in an Excel spreadsheet

1 New Member
Hi

I am attempting to connect to an excel file to check if the column names is correct (to validate that it is the file I expected) using the following code:

Expand|Select|Wrap|Line Numbers
  1. dim cn as adodb.connection
  2. dim rs as adodb.recordset
  3. cn.open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\..\file.xls" & _
  4. ";Extended Properties=""Excel 8.0;HDR=YES"""
  5. rs.open "SELECT * FROM [Sheet1$]",cn,adOpenStatic,AdLockReadOnly
  6. msgbox rs.fields(0).name 'Success
  7. msgbox rs.fields(1).name 'Error (Item cannot be found in the collection corresponding to the requested name or ordinal)
  8.  
Now if I open the file in Excel and makes any change (like adding a character and then deleting it again), save and close file. and then run the function again. Both the msgboxes work as expected.

The Excel file in question is rather large (4 full worksheets of est. 65500 rows each and a few thousand rows on the 5th worksheet)

Any suggestions on how to make this work?
Manualy opening, changing and saving the file each time is not an option.

Have tried:
Change and update the file via code(opening the rs with adLockOptimistic)
Expand|Select|Wrap|Line Numbers
  1.  rs![Field name 1]=rs![Field name 1] 
Feb 3 '10 #1
0 997

Sign in to post your reply or Sign up for a free account.

Similar topics

9
21814
by: Phil Powell | last post by:
I am using PHP 4.3.2 to create a CSV file, however, Excel constantly views it as a single-column spreadsheet with everything in quotes, whereas OpenOffice Calc views it as a legitimate spreadsheet...
0
4434
by: harshan | last post by:
Hi I am trying to read required worksheet from excel file using perl with module spreadsheet::parseexcel and spreadsheet::writeexcel but I am unable to read it, the error I am getting is...
5
3336
by: Axial | last post by:
Question: How to select columns from Excel-generated XML when some cells are empty. I've found examples where rows are to be selected, but I can't seem to extrapolate from that to selecting...
1
8891
by: Roger Twomey | last post by:
I have a form that allows a user to upload a microsoft Excel Spreadsheet. (I am testing with one created in Excel 2000) The spreadsheet is uploaded correctly. It is then supposed to be read...
2
16815
by: Scott M. Lyon | last post by:
I currently am working on a VB.NET application that imports data from an Excel spreadsheet that the customer filled in. I used the following code to use ODBC to read the data from the...
0
6171
by: sysmanint1 | last post by:
I am a total neophyte at Visual Basic but found the following post and reply from Clint concerning a dynamic range. Also, have never "posted" to a discussion I have made a macro that works on...
2
3080
by: wstsoi | last post by:
hi I have to read images from spreadsheet, is it possible to do with php?
0
1411
by: nudrat | last post by:
I have added a reference Microsoft Excel 5.0 Object Library in my project. the code is as follows: Dim myExcel As Excel.Application ' Interface to Excel Dim myWorkBookCollection As...
3
20818
by: Will | last post by:
Can someone help with code to delete multiple columns from an excel spreadsheet? I know which columns I need to delete. The code below will delete a single column but I'm not sure how to delete...
4
1765
by: Miner Jeff | last post by:
I've written some code that reads a text file. I have a requirement that the text file also be in a format that's easy to read when it's printed. In a prior project, I had used some spreadsheet...
0
7388
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7545
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7111
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7539
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5095
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4751
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3240
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3228
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
461
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.