Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Perform action on all subset selected worksheets 2

Status
Not open for further replies.

krinid

Programmer
Jun 10, 2003
356
CA
Question:
How can one detect which worksheets are selected?

ie: if a user holds control and clicks several worksheets, how can I find out exactly which sheets are selected?
 
The collection of selected sheets:
ActiveWindow.SelectedSheets
The number of sheets:
n = ActiveWindow.SelectedSheets.Count
i-th sheet selected:
ActiveWindow.SelectedSheets.Item(i)

combo
 
Excellent! Thanks. Is there no way to access this information using a workbook object? I want to make sure that the sheets selected in the activewindow actually belong to the workbook (WB) being processed in the macro. I suppose I could check to see if ActiveWindow.SelectedSheets(x).parent.name = WB.name and if not, it's a different book.
 
Hi krinid,

Do you know something I don't? (well, you probably do [smile]). I thought you could only have one workbook in a window - you might have more than one window on a workbook but not the other way round.

Enjoy,
Tony
 
My concern is that the sub could end up processing sheets in a different book altogether. I can check this as I mentioned in my last message, although I suppose ActiveWindow.parent.name = WB.name is better than what I wrote (that's what you were trying to tell me wasn't it? Sorry, I sort of tangented off here).

I guess I'm satisfied knowing I can at least 'check' to see if the sheets are in the proper workbook, but not 100% since I can't enforce it...

or wait...

after WorkbookA.Activate, ActiveWindow.SelectedSheets could only refer to WorkbookA ...

I do believe this solves my problem. Just needed to talk through it--thanks Tony, thanks Combo!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top