Getting Excel worksheet names using DAO. 
Author Message
 Getting Excel worksheet names using DAO.

Is there a way to use DAO to get the worksheet names in a Excel file?

TIA.

Pat Green

-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.*-*-*.com/ - The #1 Newsgroup Service in the World!
-----==  Over 80,000 Newsgroups - 16 Different Servers! =-----



Tue, 02 Nov 2004 03:16:35 GMT  
 Getting Excel worksheet names using DAO.
Sure,

They show up as "tables"

Steve

Public Sub ExcelOpenWbAsTable()
   On Error GoTo ProcError
   Dim db As Database
   Dim tdf As TableDef
   Dim strFile As String

   strFile = "c:\temp\sample.xls"

   Set db = OpenDatabase(strFile, False, False, "Excel 5.0;HDR=NO;IMEX=2;")
   For Each tdf In db.TableDefs

      MsgBox tdf.Name   'show sheet name

   Next

   Set db = Nothing
   Exit Sub

ProcError:
   Select Case Err.Number
         'Case 3265 'Application-defined or object-defined error
         '   Resume Next
      Case Else
         MsgBox "Unanticipated error: " & Err.Number & " " & Err.Description
         Stop
         Resume 0
   End Select
End Sub

Quote:
> Is there a way to use DAO to get the worksheet names in a Excel file?

> TIA.

> Pat Green

> -----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
> http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
> -----==  Over 80,000 Newsgroups - 16 Different Servers! =-----



Tue, 02 Nov 2004 03:31:14 GMT  
 Getting Excel worksheet names using DAO.
Dim XLA As Object, XLB As Object
Dim i As Long
Set XLA = CreateObject("Excel.Application")
Set XLB = XLA.Workbooks.Open("MyExelBookPath.xls")
For i = 1 To XLB.Sheets.Count
  Debug.Print XLB.Sheets(i).Name
Next i
XLB.Close True
XLA.Quit

---
Serge Gavrilov
http://accesstools.narod.ru



Quote:
> Is there a way to use DAO to get the worksheet names in a Excel file?

> TIA.

> Pat Green

> -----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
> http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
> -----==  Over 80,000 Newsgroups - 16 Different Servers! =-----



Tue, 02 Nov 2004 03:37:17 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Using DAO to create new Excel worksheet - Type property lost

2. Getting excel sheet names with DAO

3. Getting excel sheet names with DAO

4. Getting data from security-enabled Access 2 to Excel 7 using DAO

5. OLE: Excel worksheet without using Excel

6. How can I open Excel workbook without using Excel.Worksheet

7. Import Excel worksheets via VB and DAO?

8. Getting the list of Excel Sheet Names using VBA

9. Getting Data from Excel Worksheets

10. Getting Text Alignment from Excel Worksheet

11. HELP! Getting data to Excel Worksheet

12. Exporting Access tbl to Excel - Worksheet Names

 

 
Powered by phpBB® Forum Software