Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 238
Default detecting a proteced workbook

I can hide a single Worksheet.

Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
Worksheets(1).Visible = False
' Worksheets(1).Visible = True
End Sub

I want to hide a single Worksheet, but only when the Workbook is
protected. How do I detect a protected workbook?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default detecting a proteced workbook

Hi,

Try this

With ActiveWorkbook
IsProtected = .ProtectStructure Or .ProtectWindows
End With

Mike

"Fan924" wrote:

I can hide a single Worksheet.

Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
Worksheets(1).Visible = False
' Worksheets(1).Visible = True
End Sub

I want to hide a single Worksheet, but only when the Workbook is
protected. How do I detect a protected workbook?

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 238
Default detecting a proteced workbook

Worksheets(4).Visible = False
If ActiveWorkbook.ProtectStructure = False Then
Worksheets(4).Visible = True
End If

But it doesn't work. After the workbook is protected, you are blocked
from changing the sheet visiility.
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default detecting a proteced workbook

Hi,

You asked how to detect if a workbook is protected and the answer I gave you
does that. You must un-protect to hide the sheet then r-protect

Sub Sonic()
With ActiveWorkbook
isprotected = .ProtectStructure Or .ProtectWindows
End With
If isprotected Then
ActiveWorkbook.Unprotect
Sheets("Sheet1").Visible = False
ActiveWorkbook.Protect
Exit Sub
End If
End Sub

Mike

"Fan924" wrote:

Worksheets(4).Visible = False
If ActiveWorkbook.ProtectStructure = False Then
Worksheets(4).Visible = True
End If

But it doesn't work. After the workbook is protected, you are blocked
from changing the sheet visiility.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default detecting a proteced workbook

Perhaps your looking for something like this

Sub Sonic()
With ActiveWorkbook
isprotected = .ProtectStructure Or .ProtectWindows
End With
If isprotected Then
ActiveWorkbook.Unprotect
Sheets("Sheet1").Visible = False
ActiveWorkbook.Protect Structu=True
Else
Sheets("Sheet1").Visible = True
End If
End Sub

Mike

"Mike H" wrote:

Hi,

You asked how to detect if a workbook is protected and the answer I gave you
does that. You must un-protect to hide the sheet then r-protect

Sub Sonic()
With ActiveWorkbook
isprotected = .ProtectStructure Or .ProtectWindows
End With
If isprotected Then
ActiveWorkbook.Unprotect
Sheets("Sheet1").Visible = False
ActiveWorkbook.Protect
Exit Sub
End If
End Sub

Mike

"Fan924" wrote:

Worksheets(4).Visible = False
If ActiveWorkbook.ProtectStructure = False Then
Worksheets(4).Visible = True
End If

But it doesn't work. After the workbook is protected, you are blocked
from changing the sheet visiility.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Not detecting Open Workbook - Why Roger Excel Discussion (Misc queries) 7 January 26th 08 08:16 PM
Detecting open workbook Nigel RS[_2_] Excel Programming 2 September 13th 07 07:28 AM
Detecting the workbook name on startup bigmart Excel Programming 2 December 20th 06 04:58 AM
Detecting a another workbook has opended Nigel Excel Programming 1 May 7th 05 08:19 AM
Detecting workbook activation Jack Wolf Excel Programming 0 July 26th 03 01:10 AM


All times are GMT +1. The time now is 12:45 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"