
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
:
:
:
:
:
:
:
:
: