Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default unprotecting my worksheet

Hello everyone,

I have a worksheet which works great except i wish to distribute it and so
want to protect it with a password. so far so easy but the next day when i
want to amend it and redistribute it i need to unprotect it again.

Dim strSharePwd as string

If ActiveSheet.Protect Then
'strSharePwd = InputBox("Enter password To protect")
ActiveSheet.Unprotect Password:=strSharePwd
Else
strSharePwd = InputBox("Enter password To protect")
ActiveSheet.Protect Password:=strSharePwd
End If


Ive got an ActiveXcontrol on the spreadsheet which should ask for the
password to be supplied either to protect or unprotect using the following
code but instead it only wishes to protect. My if statement doesnt seem to
funnel towards unprotecting.

Can anyone help?

With thanks,

Amit
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 137
Default unprotecting my worksheet

Hi,

Is there an apostrophy in from on the 'strSharePwd for a reason?

Greg


DowningDevelopments wrote:
Hello everyone,

I have a worksheet which works great except i wish to distribute it and so
want to protect it with a password. so far so easy but the next day when i
want to amend it and redistribute it i need to unprotect it again.

Dim strSharePwd as string

If ActiveSheet.Protect Then
'strSharePwd = InputBox("Enter password To protect")
ActiveSheet.Unprotect Password:=strSharePwd
Else
strSharePwd = InputBox("Enter password To protect")
ActiveSheet.Protect Password:=strSharePwd
End If


Ive got an ActiveXcontrol on the spreadsheet which should ask for the
password to be supplied either to protect or unprotect using the following
code but instead it only wishes to protect. My if statement doesnt seem to
funnel towards unprotecting.

Can anyone help?

With thanks,

Amit


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 182
Default unprotecting my worksheet

Hi Downing,

Try to use this one :

Dim strSharePwd as string
'this "Un&protect Sheet..." is case sensitives ...
If CommandBars("protection"). _
FindControl(ID:=893).Caption = "Un&protect Sheet..." Then
strSharePwd = InputBox("Enter password To protect")
ActiveSheet.Unprotect Password:=strSharePwd
Else
strSharePwd = InputBox("Enter password To protect")
ActiveSheet.Protect Password:=strSharePwd
End If

That will check wether sheet is protect or not by finding out the caption of
commandbars ...
--

Regards,

Halim


"DowningDevelopments" wrote:

Hello everyone,

I have a worksheet which works great except i wish to distribute it and so
want to protect it with a password. so far so easy but the next day when i
want to amend it and redistribute it i need to unprotect it again.

Dim strSharePwd as string

If ActiveSheet.Protect Then
'strSharePwd = InputBox("Enter password To protect")
ActiveSheet.Unprotect Password:=strSharePwd
Else
strSharePwd = InputBox("Enter password To protect")
ActiveSheet.Protect Password:=strSharePwd
End If


Ive got an ActiveXcontrol on the spreadsheet which should ask for the
password to be supplied either to protect or unprotect using the following
code but instead it only wishes to protect. My if statement doesnt seem to
funnel towards unprotecting.

Can anyone help?

With thanks,

Amit

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default unprotecting my worksheet

You code currently calls the Method to protect a worksheet (without a
password). It does not have a return value, so your If test evaluates to
false and you always get the "Enter password To protect" branch of code
executed.
It does not test if the WS is protected.

For that you one/more of these Or'd together
ActiveSheet.ProtectContents=True
..ProtectDrawingObjects
..ProtectScenarios

If ActiveSheet.ProtectContents = True Then
'strSharePwd = InputBox("Enter password To protect")
ActiveSheet.Unprotect Password:=strSharePwd
Else
strSharePwd = InputBox("Enter password To protect")
ActiveSheet.Protect Password:=strSharePwd
End If

NickHK

"DowningDevelopments" wrote
in message ...
Hello everyone,

I have a worksheet which works great except i wish to distribute it and so
want to protect it with a password. so far so easy but the next day when i
want to amend it and redistribute it i need to unprotect it again.

Dim strSharePwd as string

If ActiveSheet.Protect Then
'strSharePwd = InputBox("Enter password To protect")
ActiveSheet.Unprotect Password:=strSharePwd
Else
strSharePwd = InputBox("Enter password To protect")
ActiveSheet.Protect Password:=strSharePwd
End If


Ive got an ActiveXcontrol on the spreadsheet which should ask for the
password to be supplied either to protect or unprotect using the following
code but instead it only wishes to protect. My if statement doesnt seem to
funnel towards unprotecting.

Can anyone help?

With thanks,

Amit



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default unprotecting my worksheet

Thanks guys, Halim's suggestions works great for me

"Halim" wrote:

Hi Downing,

Try to use this one :

Dim strSharePwd as string
'this "Un&protect Sheet..." is case sensitives ...
If CommandBars("protection"). _
FindControl(ID:=893).Caption = "Un&protect Sheet..." Then
strSharePwd = InputBox("Enter password To protect")
ActiveSheet.Unprotect Password:=strSharePwd
Else
strSharePwd = InputBox("Enter password To protect")
ActiveSheet.Protect Password:=strSharePwd
End If

That will check wether sheet is protect or not by finding out the caption of
commandbars ...
--

Regards,

Halim


"DowningDevelopments" wrote:

Hello everyone,

I have a worksheet which works great except i wish to distribute it and so
want to protect it with a password. so far so easy but the next day when i
want to amend it and redistribute it i need to unprotect it again.

Dim strSharePwd as string

If ActiveSheet.Protect Then
'strSharePwd = InputBox("Enter password To protect")
ActiveSheet.Unprotect Password:=strSharePwd
Else
strSharePwd = InputBox("Enter password To protect")
ActiveSheet.Protect Password:=strSharePwd
End If


Ive got an ActiveXcontrol on the spreadsheet which should ask for the
password to be supplied either to protect or unprotect using the following
code but instead it only wishes to protect. My if statement doesnt seem to
funnel towards unprotecting.

Can anyone help?

With thanks,

Amit

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
Unprotecting a worksheet Jessica Excel Worksheet Functions 8 August 21st 08 06:43 PM
Unprotecting a Protect Worksheet Henry A. Excel Worksheet Functions 0 December 13th 07 02:55 PM
Unprotecting a Worksheet Anney Excel Worksheet Functions 7 August 4th 07 01:14 PM
Unprotecting a Protect Worksheet Ang Excel Worksheet Functions 1 January 11th 07 12:52 AM
unprotecting a worksheet Randy123 Excel Discussion (Misc queries) 1 August 8th 05 06:11 PM


All times are GMT +1. The time now is 09:34 AM.

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

About Us

"It's about Microsoft Excel"