473,320 Members | 1,861 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

How to import always the FIRST available sheet from EXCEL-File

I am importing data from an EXCEL XLS-File via OLEDB-Provider

The command is SELECT * from [sheet1]
Everything works fine if the first sheet is named sheet1

But sometimes the name is not known by my application and the import failes.

Is it possible to import always the FIRST available sheet ??



May 12 '06 #1
1 2179
On Fri, 12 May 2006 09:14:44 +0200, "Peter Stojkovic" <ds*@gmx.net> wrote:

¤ I am importing data from an EXCEL XLS-File via OLEDB-Provider
¤
¤ The command is SELECT * from [sheet1]
¤
¤
¤ Everything works fine if the first sheet is named sheet1
¤
¤
¤
¤ But sometimes the name is not known by my application and the import failes.
¤
¤ Is it possible to import always the FIRST available sheet ??

There are only two ways, of which I am aware, that will enable you to retrieve an Excel Worksheet by
its ordinal position in the Workbook. First method is to use DAO:

Dim xlWB As DAO.Database
Dim strFirstSheetName As String

xlWB = OpenDatabase("C:\Test Files\Book10.xls", False, True, "Excel 8.0;")

strFirstSheetName = xlWB.TableDefs(0).Name

xlWB.Close

....and the other is to use automation with Microsoft Excel:

Dim obj As Excel.Application
Dim objWB As Excel.Workbook
Dim strFirstSheetName As String

obj = CreateObject("Excel.Application")
objWB = obj.Workbooks.Open("C:\Test Files\Book10.xls")

strFirstSheetName = objWB.Worksheets(1).Name

objWB.Close
objWB = Nothing
obj.Quit
obj = Nothing
Now if the Workbook only contains a single Worksheet then there is a native .NET method that does
not require COM automation or the use of DAO.
Paul
~~~~
Microsoft MVP (Visual Basic)
May 12 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Nick M | last post by:
Hello All, Excellent info here Thanks! I am very new to using access in general and I am on a learning curve. I'm trying to import an excel workbook (with worksheets) into an access db via a...
10
by: Niklas | last post by:
Hi Before I start coding I need to be sure that nobody else has not done it yet and that I can use it. I need an import utility which import data from Excel to a database or some object in...
8
by: FireGeek | last post by:
I have a database that is split appropriately. Annually, we need to add data from .xls files. I have added code so with a click of a button, it will import this data as a new table into the...
1
by: DThreadgill | last post by:
I have a spreadsheet with about 35 tabs that I need to import into one table in Access. I found this link http://www.thescripts.com/forum/thread650662-import+multiple+tabs.html and changed some...
7
by: TG | last post by:
hi! I am trying to create a sql server table from an excel sheet. Here is the code I have: 'This procedure the xlsx file and dumps it to a table in SQL Server
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.