Warning Message (at open) if Multiple Sheets are Selected

D

Dave

Is there a macro/code that will warn me when multiple sheets are selected
when I open a file? A lot of my files have 10+ tabs with long names so I
don't necessarily see all of the active tabs. So if I happened to save the
file with multiple tabs selected and then reopen it and start working
(without checking), I overwrite information I didn't intend to overwrite. I
have seen the msgbox activewindow.selectedsheets.count code but I don't know
where to put it in VB.

Any help is appreciated.

Thanks
 
J

John C

you could just have vba code that when you open the workbook always goes to a
specific tab, then you wouldn't have to worry about whether or not multiple
tabs were selected.
 
D

Dave Peterson

You could add this procedure to every workbook's project that you need (in a
general module):

Option Explicit
Sub Auto_Open()
if activewindow.selectedsheets.count > 1 then
msgbox "Be careful--multiple sheets selected"
end if
End Sub

If you're new to macros:

Debra Dalgleish has some notes how to implement macros here:
http://www.contextures.com/xlvba01.html

David McRitchie has an intro to macros:
http://www.mvps.org/dmcritchie/excel/getstarted.htm

Ron de Bruin's intro to macros:
http://www.rondebruin.nl/code.htm

(General, Regular and Standard modules all describe the same thing.)
 
D

Dave

Thank you for the information. I don't know VB beyond what I get from this
forum. What is the code I would input and where would I input it in the VB
editor to specify the file open to a specific sheet?

Thanks
 
G

Gord Dibben

With your workbook open, right-click on the Excel Icon left of "File" on
worksheet menubar.

Select "View Code" and paste this into the module that opens.

Private Sub Workbook_Open()
If ActiveWindow.SelectedSheets.Count > 1 Then
Sheets("Sheet1").Select
'otherwise it will open to last active sheet when saved
End If
End Sub


Gord Dibben MS Excel MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top