Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2003
    Location
    Harrow, UK
    Posts
    53

    Unanswered: 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

  2. #2
    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

  3. #3
    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

  4. #4
    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?

Posting Permissions

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