Here's a UDF which returns a collection of worksheet names. It takes an
optional parameter for the workbook. If not specified, it defaults to the
ActiveWorkbook.
Function GetWorksheets(Optional ByVal wkb As Workbook = Nothing) As
Collection
Dim wks As Worksheet
' Default to ActiveWorkbook
If wkb Is Nothing Then Set wkb = ActiveWorkbook
Set GetWorksheets = New Collection
For Each wks In wkb.Worksheets
GetWorksheets.Add wks.Name
Next
End Function
' Sample access code
Sub Tester()
Dim n As Long, c As New Collection
Set c = GetWorksheets ' No workbook specified, so default to
ActiveWorkbook
' Set c = GetWorksheets(ActiveWorkbook) ' Alternative way to get the
ActiveWorkbook
' Set c = GetWorksheets(Workbooks("Book2.xls")) ' Or specify a
particular workbook
For n = 1 To c.Count
Debug.Print c(n)
Next
End Sub
--
Tim Zych
http://www.higherdata.com
Workbook Compare - Excel data comparison utility
Free and Pro versions
"Bassman62" wrote in message
...
Using xl-2007;
Is there a UDF one could use to return all of the names of the worksheets
in
the active workbook?
Thanks.