Getting the list of Excel Sheet Names using VBA 
Author Message
 Getting the list of Excel Sheet Names using VBA

I tried the following code from within MS Access 97 and am having some
difficulty. Doesn't seem to want to work.
Any thoughts?

Thanks!

Sub AutomateExcel()
' This procedure is a brief sample showing
' how to automate Excel.

' Remember to set a reference to the most current available
' Microsoft Excel object library.

    ' Declare object variables.
    Dim appXl As Excel.Application
    Dim wrkFile As Excel.Workbooks
    'Dim wks As Excel.Sheets

    ' Set object variables.
    Set appXl = New Excel.Application
    Set wrkFile = appXl.Workbooks

    ' Open a file.
    wrkFile.Open "c:\Dave.xls"
    ' Display Excel.
    For Each wks In wrkFile
        Debug.Print (wrkFile!Name)
    Next wks

    appXl.Visible = True
    MsgBox "At this point Excel is open and displays a document." & Chr$(13)
& _
    "The following statements will close the document and then close Excel."
    ' Close the file.
    wrkFile.Close
    ' Quit Excel.
    appXl.Quit

    ' Close the object references.
    Set wrkFile = Nothing
    Set appXl = Nothing

End Sub



Sat, 10 Feb 2001 03:00:00 GMT  
 Getting the list of Excel Sheet Names using VBA
Hi John,

Try this modified version

'********** Code start *********
Sub AutomateExcel()
' This procedure is a brief sample showing
' how to automate Excel.

' Remember to set a reference to the most current available
' Microsoft Excel object library.

    ' Declare object variables.
    Dim appXl As Excel.Application
    Dim wrkFile As Excel.Workbook
    Dim wks As Excel.Worksheet

    ' Set object variables.
    Set appXl = New Excel.Application
    Set wrkFile = appXl.Workbooks.Open("c:\temp\test.xls")

    ' Display Excel.
    appXl.Visible = True

    For Each wks In wrkFile.Worksheets
        Debug.Print wks.Name
    Next wks

    MsgBox "At this point Excel is open and displays a document." & Chr$(13)
& _
            "The following statements will close the document and then close
Excel."
    ' Close the file.
    wrkFile.Close
    ' Quit Excel.
    appXl.Quit

    ' Close the object references.
    Set wrkFile = Nothing
    Set appXl = Nothing

End Sub
'*********** Code End ***********

HTH
--
Dev Ashish (Just my $.001)
---------------
The Access Web ( http://home.att.net/~dashish )
---------------

:
:I tried the following code from within MS Access 97 and am having some
:difficulty. Doesn't seem to want to work.
:Any thoughts?
:
:Thanks!
:
:
:Sub AutomateExcel()
:' This procedure is a brief sample showing
:' how to automate Excel.
:
:' Remember to set a reference to the most current available
:' Microsoft Excel object library.
:
:    ' Declare object variables.
:    Dim appXl As Excel.Application
:    Dim wrkFile As Excel.Workbooks
:    'Dim wks As Excel.Sheets
:
:    ' Set object variables.
:    Set appXl = New Excel.Application
:    Set wrkFile = appXl.Workbooks
:
:    ' Open a file.
:    wrkFile.Open "c:\Dave.xls"
:    ' Display Excel.
:    For Each wks In wrkFile
:        Debug.Print (wrkFile!Name)
:    Next wks
:
:
:    appXl.Visible = True
:    MsgBox "At this point Excel is open and displays a document." &
Chr$(13)
:& _
:    "The following statements will close the document and then close
Excel."
:    ' Close the file.
:    wrkFile.Close
:    ' Quit Excel.
:    appXl.Quit
:
:    ' Close the object references.
:    Set wrkFile = Nothing
:    Set appXl = Nothing
:
:End Sub
:
:
:
:
:
:
:
:
:



Sat, 10 Feb 2001 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. getting the name of the active sheet (Excel)

2. Getting excel sheet names with DAO

3. getting sheet name in excel

4. Getting excel sheet names with DAO

5. Use VBA to send Task Folder name to an Excel Sheet

6. VB or Excel VBA, accessing list of all the sheets in a workbook

7. Using Excel spread sheet with list box...

8. Getting Excel worksheet names using DAO.

9. Getting function and procedure names using VBA

10. Getting a list of table names using VBSQL?.?

11. Getting a List of tables using VBA??

12. getting previous cell values in excel sheets

 

 
Powered by phpBB® Forum Software