ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   list the sheets in a workbook (https://www.excelbanter.com/excel-programming/318028-list-sheets-workbook.html)

Listing of Excel shhets in a workbook

list the sheets in a workbook
 
I need to be able to list the names of the sheets contained in a workbook.

Jason M[_2_]

list the sheets in a workbook
 
here is a vb.net example that should work for ya.

Dim sheet As Excel.Worksheet
Dim ODOC As Excel.Workbook

................

Dim worksheetname As String
For Each sheet In ODOC.Worksheets
Console.WriteLine(sheet.Name)
Next

"Listing of Excel shhets in a workbook" wrote:

I need to be able to list the names of the sheets contained in a workbook.


AA2e72E

list the sheets in a workbook
 
Function ListSheets() As String
For Each sht In ActiveWorkbook.Sheets
ListSheets = ListSheets & "," & sht.Name
Next
End Function

Sub aa()
MsgBox Mid(ListSheets, 2)
End Sub

Run the sub aa to get a comma delimited string containing the names of the
sheets. If you want to include worksheets only, replace ActiveWorkbook.Sheets
by ActiveWorkbook.Worksheets.

"Listing of Excel shhets in a workbook" wrote:

I need to be able to list the names of the sheets contained in a workbook.


Jason Murray

list the sheets in a workbook
 

Dim ODOC As Excel.Workbook
Dim sheet As Excel.Worksheet

.......
Dim worksheetname As String
For Each sheet In ODOC.Worksheets
Console.WriteLine(sheet.Name)
Next

"Listing of Excel shhets in a workbook" wrote:

I need to be able to list the names of the sheets contained in a workbook.


Tom Ogilvy

list the sheets in a workbook
 
sStr = ""
for each sh in Activeworkbook.sheets
sStr = sStr & sh.Name & vbNewLine
Next
msgBox sStr

--
Regards,
Tom Ogilvy

"Listing of Excel shhets in a workbook" <Listing of Excel shhets in a
wrote in message
...
I need to be able to list the names of the sheets contained in a workbook.




Alan Beban[_2_]

list the sheets in a workbook
 
Listing of Excel shhets in a workbook wrote:
I need to be able to list the names of the sheets contained in a workbook.

Here are a couple of ways:

Sub qwerty4()
'Workbook must have reference to Microsoft Scripting Runtime
Dim dic As Dictionary, rng As Range
Set dic = New Dictionary
Set rng = Range("A1:A" & ActiveWorkbook.Sheets.Count)
For Each sh In ActiveWorkbook.Sheets
dic.Add CStr(sh.Name), sh.Name
Next
rng.Value = Application.Transpose(dic.Items)
End Sub

Sub qwerty5()
Dim arr, rng As Range
Dim i As Integer, n As Integer, m As Object
Set m = ActiveWorkbook.Sheets
n = m.Count
Set rng = Range("A1:A" & n)
ReDim arr(1 To n, 1 To 1)
i = 1
For Each sh In m
arr(i, 1) = sh.Name
i = i + 1
Next
rng.Value = arr
End Sub

Alan Beban


All times are GMT +1. The time now is 06:54 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com