[RESOLVED] Get First Excel Worksheet name
I've tried using the following but it is returning the names alphabetically any ideas on how to get the first sheet in the workbook's name without using the excel object?
vb Code:
Dim objConn As OleDb.OleDbConnection
Dim dt As DataTable = Nothing
Try
objConn = Connect()
dt = objConn.GetOleDbSchemaTable(OleDb.OleDbSchemaGuid.Tables, Nothing)
Close(objConn)
Return dt.Rows(0).Item("TABLE_NAME").ToString.Replace("''", "'")
Catch ex As Exception
Return Nothing
Finally
If Not dt Is Nothing Then
dt.Dispose()
End If
If Not objConn Is Nothing Then
Close(objConn)
End If
End Try
Re: Get First Excel Worksheet name
vb Code:
'booo had to use DAO
Dim ExcelWB As DAO.Database
Dim tbl As DAO.TableDef
Dim JetEngine As New dao.DBEngine
Dim SheetName As String
ExcelWB = JetEngine.OpenDatabase(fileName, False, True, "Excel 8.0;")
For Each tbl In ExcelWB.TableDefs
SheetName = tbl.Name
Exit For
Next tbl
ExcelWB.Close()
see comment :(
Re: Get First Excel Worksheet name
Hey,
Does that mean you have been able to solve your problem?
If so, remember to mark your thread as resolved.
Gary
Re: [RESOLVED] Get First Excel Worksheet name
thanks, yeah was trying to leave it open to see if anyone came up with a better solution but I'll stick with the DAO one.