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
Solved

Retrieve the names of worksheets and display them in a MsgBox

Posted on 2013-12-15
5
188 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
  • 2
  • 2
5 Comments
 
LVL 46

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 46

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Drop Down List with Unique/Distinct Values (Part II - ComboBox or ListBox and Data Validation List Bonus!) David Miller (dlmille) Intro This article focuses on delivering unique, sorted lists to list objects (e.g., ComboBox, ListBox) and Dat…
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

860 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