?
Solved

Which worksheet is active...

Posted on 2004-11-08
3
Medium Priority
?
162 Views
Last Modified: 2010-05-02
For i=1 to wb.Worksheets.count
Set ws=wb.Worksheets(i)
if ws.Selected=True Then MsgBox ws.Name '<-- this code doen't give the active or selected ws name.
Next i

What is correct code to do this?

Thanks.
0
Comment
Question by:Mike Eghtebas
  • 2
3 Comments
 
LVL 5

Expert Comment

by:RogueSolutions
ID: 12527757
The ActiveSheet object will always have the active sheet.  Can get it's .Name property
0
 
LVL 5

Accepted Solution

by:
RogueSolutions earned 1000 total points
ID: 12527766
To clarify ...

msgbox wb.ActiveSheet.Name
0
 
LVL 8

Expert Comment

by:ampapa
ID: 12527889
As RougeSolutions said,

Dim i As Integer
Dim ws As Worksheet
Dim wb As Workbook

Set wb = ActiveWorkbook

For i = 1 To wb.Worksheets.Count
    Set ws = wb.Worksheets(i)
    If ws.Name = "Sheet2" Then MsgBox ws.Name '<-- this code doen't give the active or selected ws name.
Next i
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

850 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