PC Review


Reply
Thread Tools Rate Thread

detecting a proteced workbook

 
 
Fan924
Guest
Posts: n/a
 
      10th Dec 2008
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?
 
Reply With Quote
 
 
 
 
Mike H
Guest
Posts: n/a
 
      10th Dec 2008
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?
>

 
Reply With Quote
 
Fan924
Guest
Posts: n/a
 
      10th Dec 2008
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 With Quote
 
Mike H
Guest
Posts: n/a
 
      10th Dec 2008
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 With Quote
 
Mike H
Guest
Posts: n/a
 
      10th Dec 2008
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 Structure:=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 With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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 Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Not detecting Open Workbook - Why Roger Microsoft Excel Misc 7 26th Jan 2008 08:16 PM
Detecting open workbook =?Utf-8?B?TmlnZWwgUlM=?= Microsoft Excel Programming 2 13th Sep 2007 07:28 AM
Detecting the workbook name on startup bigmart Microsoft Excel Programming 2 20th Dec 2006 04:58 AM
Detecting a another workbook has opended Nigel Microsoft Excel Programming 1 7th May 2005 08:19 AM
Detecting workbook activation Jack Wolf Microsoft Excel Programming 0 26th Jul 2003 01:10 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:46 AM.