Results 1 to 4 of 4
  1. #1
    2 Star Lounger
    Join Date
    May 2002
    Location
    Atlanta, Georgia, USA
    Posts
    124
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Testing for selected sheets (2000)

    HI!

    Is there a way with VBA to determine if the user has selected multiple sheets?

    I would like to determine at the beginning of the macro which sheets are selected and repeat the same code on each sheet. I can't find anything in the object model that seems to allow me to do that. It seems that ActiveSheet is only the active sheet (duh!), and I can't return a range of selected sheets.

    I expect that since I can select more than one sheet with the mouse, there ought to be an equivalent mechanism in the code.

    Thanks!
    Bob
    Writing Consultant / Word Template Designer
    Words Connect

  2. #2
    3 Star Lounger
    Join Date
    Dec 2000
    Location
    NJ, USA
    Posts
    239
    Thanks
    2
    Thanked 1 Time in 1 Post

    Re: Testing for selected sheets (2000)

    ActiveWindow.SelectedSheets is what I think you need. ActiveWindow.SelectedSheets.Count would tell you how many sheets are selected, or you could use something like For each wks in ActiveWindow.SelectedSheets to cycle through them.

    Colin.

  3. #3
    3 Star Lounger
    Join Date
    Jul 2001
    Location
    Long Beach, California, USA
    Posts
    233
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Testing for selected sheets (2000)

    damn....never fast enough. I found some code in a book by Kofler, which I tweaked:
    <pre>Sub HowManySelected()
    Dim sh As Worksheet
    Dim shList As Object
    Dim shCount As Integer
    Dim sName As String
    Dim sAllNames As String

    Set shList = ActiveWindow.SelectedSheets
    shCount = shList.Count

    If shCount > 1 Then
    For Each sh In shList
    sName = sh.Name
    sAllNames = sAllNames & " " & sName
    Next sh
    End If

    MsgBox shCount & vbCrLf & sAllNames
    End Sub
    </pre>


  4. #4
    2 Star Lounger
    Join Date
    May 2002
    Location
    Atlanta, Georgia, USA
    Posts
    124
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Testing for selected sheets (2000)

    Cool!

    That's exactly what I was looking for.

    Thanks!
    Bob
    Writing Consultant / Word Template Designer
    Words Connect

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •