If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Excel > Excel VBA: How to ensure only one sheet selected

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-13-07, 02:44
jamesmc2 jamesmc2 is offline
Registered User
 
Join Date: Jul 2003
Location: Harrow, UK
Posts: 53
Excel VBA: How to ensure only one sheet selected

I have a Workbook with several sheets.
Sometimes more than one sheet will already be selected when it's opened.

I want to unprotect the Workbook using :

'Unprotect it if it's protected
If sht.ProtectContents = True Then
ActiveSheet.Unprotect
End If

which works fine, PROVIDED that there is only one sheet selected.

So how do i make sure in my code that only 1 sheet is selected? I will never know which sheet(s) are selected in advance, so coding the selection of one particular sheet won't always work, because, if you select a sheet which is one of (say) three selected, all three remain selected, you just change which one is active.
__________________
Thank you,
James
Reply With Quote
  #2 (permalink)  
Old 06-18-07, 22:27
savbill savbill is offline
Registered User
 
Join Date: Feb 2004
Posts: 533
Activating a sheet where multiple sheets are selected would not unselect the selected sheets.

ActiveWorkbook.Sheets(3).Activate 'This only activates a worksheet it will not ensure only one sheet is selected.

Using the Select statement will always select only one worksheet whether there is only one selected or multiple worksheets selected. Use Sheets(1).Select whenever the workbook is opened and you will ensure only one sheet is selected.

ActiveWorkbook.Sheets(1).Select
__________________
~

Bill
Reply With Quote
  #3 (permalink)  
Old 06-21-07, 10:09
jamesmc2 jamesmc2 is offline
Registered User
 
Join Date: Jul 2003
Location: Harrow, UK
Posts: 53
Oh of course - it's obvious when you think about it. Thank you very much.

*wanders off, kicking self*
__________________
Thank you,
James
Reply With Quote
  #4 (permalink)  
Old 07-15-07, 15:54
norie norie is offline
Registered User
 
Join Date: Mar 2006
Posts: 163
James

You shouldn't need to use Select or Activate.

How exactly are the sheets being selected when the workbook is opened, and what sheet to you actually want to unprotect?
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On