Results 1 to 4 of 4

Thread: [RESOLVED] Get First Excel Worksheet name

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2001
    Location
    Mass USA
    Posts
    1,674

    Resolved [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:
    1. Dim objConn As OleDb.OleDbConnection
    2.         Dim dt As DataTable = Nothing
    3.  
    4.         Try
    5.             objConn = Connect()
    6.             dt = objConn.GetOleDbSchemaTable(OleDb.OleDbSchemaGuid.Tables, Nothing)
    7.             Close(objConn)
    8.             Return dt.Rows(0).Item("TABLE_NAME").ToString.Replace("''", "'")
    9.         Catch ex As Exception
    10.             Return Nothing
    11.         Finally
    12.             If Not dt Is Nothing Then
    13.                 dt.Dispose()
    14.             End If
    15.             If Not objConn Is Nothing Then
    16.                 Close(objConn)
    17.             End If
    18.         End Try

  2. #2

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2001
    Location
    Mass USA
    Posts
    1,674

    Re: Get First Excel Worksheet name

    vb Code:
    1. 'booo had to use DAO
    2.         Dim ExcelWB As DAO.Database
    3.         Dim tbl As DAO.TableDef
    4.         Dim JetEngine As New dao.DBEngine
    5.         Dim SheetName As String
    6.         ExcelWB = JetEngine.OpenDatabase(fileName, False, True, "Excel 8.0;")
    7.         For Each tbl In ExcelWB.TableDefs
    8.             SheetName = tbl.Name
    9.             Exit For
    10.         Next tbl
    11.  
    12.         ExcelWB.Close()

    see comment

  3. #3
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    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

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2001
    Location
    Mass USA
    Posts
    1,674

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width