|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
How to import always the FIRST available sheet from EXCEL-FileI 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 ?? On Fri, 12 May 2006 09:14:44 +0200, "Peter Stojkovic" <d**@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)
Multiple fields in a single textbox
Image Resource - not released DataViews with DataSets 'Incremental Search' of data base or "Wheres the 'Seek' method Reading and Writing Text Files Problem with MoveFile command in ASP page register Mouse wheel handler in main VB .net 2005 form Closing all forms at once Inherent encryption in .NET 2.0? dot.net com class function |
|||||||||||||||||||||||