Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 77
Default Re-protect if originally protected, leave unprotected if not?

I have this in my personal.xls for a button on one of my toolbars:



Sub FillDownWithNumberSeries()
'
Selection.DataSeries Rowcol:=xlColumns, Type:=xlLinear, Date:=xlDay, _
Step:=1, Trend:=False
End Sub



It's worked very well until now because I have never had protected sheets.
Now I have difficulty using if workbook is protected and am getting a little
tired of unprotecting all the time <g. I've looked in the archives and
have found example code, but I'm not good at all on the ones dealing with IF
statements yet so have not yet had success in modifying the code above to
fit this situation.

To put at the beginning of the above "ActiveSheet.Unprotect" is not a
problem as this will work in all cases, I imagine, whether protected or not
(?). What I'm stuck on is for XL2K to re-protect (i.e., via something like
"ActiveSheet.Protect") only those workbooks and sheets that were protected
to begin with. How would one do this, pls?

Thank you! :oD


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Re-protect if originally protected, leave unprotected if not?

Assuming if anything on the sheet is protected, it will include content
protection.
Sub FillDownWithNumberSeries()
'
Dim bProtected as Boolean
bProtected = False
if activesheet.ProtectContents then
bProtected = True
ActiveSheet.Unprotect
end if
Selection.DataSeries Rowcol:=xlColumns, Type:=xlLinear, Date:=xlDay, _
Step:=1, Trend:=False
if bProtected then
Activesheet.Protect
end if
End Sub

--
Regards,
Tom Ogilvy

"StargateFanFromWork" wrote in message
...
I have this in my personal.xls for a button on one of my toolbars:



Sub FillDownWithNumberSeries()
'
Selection.DataSeries Rowcol:=xlColumns, Type:=xlLinear, Date:=xlDay, _
Step:=1, Trend:=False
End Sub



It's worked very well until now because I have never had protected sheets.
Now I have difficulty using if workbook is protected and am getting a

little
tired of unprotecting all the time <g. I've looked in the archives and
have found example code, but I'm not good at all on the ones dealing with

IF
statements yet so have not yet had success in modifying the code above to
fit this situation.

To put at the beginning of the above "ActiveSheet.Unprotect" is not a
problem as this will work in all cases, I imagine, whether protected or

not
(?). What I'm stuck on is for XL2K to re-protect (i.e., via something

like
"ActiveSheet.Protect") only those workbooks and sheets that were protected
to begin with. How would one do this, pls?

Thank you! :oD




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 77
Default Re-protect if originally protected, leave unprotected if not?

Works perfectly!

I'll be able to modify all my other custom buttons now using the basics of
this code.

Thank you! :oD

"Tom Ogilvy" wrote in message
...
Assuming if anything on the sheet is protected, it will include content
protection.
Sub FillDownWithNumberSeries()
'
Dim bProtected as Boolean
bProtected = False
if activesheet.ProtectContents then
bProtected = True
ActiveSheet.Unprotect
end if
Selection.DataSeries Rowcol:=xlColumns, Type:=xlLinear, Date:=xlDay, _
Step:=1, Trend:=False
if bProtected then
Activesheet.Protect
end if
End Sub

--
Regards,
Tom Ogilvy

"StargateFanFromWork" wrote in message
...
I have this in my personal.xls for a button on one of my toolbars:



Sub FillDownWithNumberSeries()
'
Selection.DataSeries Rowcol:=xlColumns, Type:=xlLinear, Date:=xlDay,

_
Step:=1, Trend:=False
End Sub



It's worked very well until now because I have never had protected

sheets.
Now I have difficulty using if workbook is protected and am getting a

little
tired of unprotecting all the time <g. I've looked in the archives and
have found example code, but I'm not good at all on the ones dealing

with
IF
statements yet so have not yet had success in modifying the code above

to
fit this situation.

To put at the beginning of the above "ActiveSheet.Unprotect" is not a
problem as this will work in all cases, I imagine, whether protected or

not
(?). What I'm stuck on is for XL2K to re-protect (i.e., via something

like
"ActiveSheet.Protect") only those workbooks and sheets that were

protected
to begin with. How would one do this, pls?

Thank you! :oD






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
Protected/Unprotected Cells LtGator Excel Discussion (Misc queries) 0 August 10th 09 07:01 PM
Can a row containing protected & unprotected cells be copied? Jannine Excel Worksheet Functions 8 March 27th 09 02:13 PM
Unprotected cells becoming protected TomV Excel Programming 0 November 30th 05 01:42 PM
Leave list box unprotected while protecting worksheet acukid Excel Discussion (Misc queries) 1 September 13th 05 06:48 PM
Copy of protected document was unprotected in 97 and protected in 2002 Beth Mantoan Excel Programming 0 July 31st 03 10:40 PM


All times are GMT +1. The time now is 03:38 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"