Solved

Retrieve the names of worksheets and display them in a MsgBox

Posted on 2013-12-15
5
198 Views
Last Modified: 2013-12-17
Dear Experts:

On the currently open workbook I would like to perform the following action using VBA:

Retrieve the worksheets' names of all the worksheets of the currently open workbook with  the exception of the sheets named 'Main', 'Calculation' and any sheets with the default names such as 'sheet1'.

The worksheet names are to be displayed in a MsgBox. I know that there is a character limitation on MsgBoxes.

Help is much appreciated. Thank you very much in advance.

Regards, Andreas
0
Comment
Question by:AndreasHermle
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 47

Accepted Solution

by:
Martin Liss earned 350 total points
ID: 39720394
Dim ws As Worksheet
dim strNames as String

For Each ws In worksheets
    If Left(ws.Name,5) = "Sheet" or ws.Name = "Main" or ws.Name = "Calculation" Then
        ' do nothing
    Else
        strNames = strNames & ws.Name & " "
    End If
Next

MsgBox strNames

Open in new window

0
 
LVL 43

Assisted Solution

by:Saqib Husain, Syed
Saqib Husain, Syed earned 150 total points
ID: 39720402
Sub listsheets()
    Dim ws As Worksheet
    Dim wslist As String
    For Each ws In ActiveWorkbook.Worksheets
        If ws.Name <> ws.CodeName And ws.Name <> "Main" And ws.Name <> "Calculation" Then
            wslist = wslist & IIf(wslist = "", "", vbCrLf) & ws.Name
        End If
    Next ws
    MsgBox wslist
End Sub
0
 

Author Comment

by:AndreasHermle
ID: 39720466
Hi ssaqibh,

the sheet names are nicely listed in your msgbox although I am afraid to tell you that the msgbox still lists 'Sheet1'. ws.CodeName does not seem to work.

Martin: Great job. Works just fine. Thank you very much.


Regards, Andreas
0
 

Author Closing Comment

by:AndreasHermle
ID: 39723368
Dear both,

great job from both of you. By combining the codes I am getting exactly the result I was looking for.

Regards, Andreas
0
 
LVL 47

Expert Comment

by:Martin Liss
ID: 39724485
You're welcome and I'm glad I was able to help.

Marty - MVP 2009 to 2013
0

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question