Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,646
Default is ws protected with a given password?

Hi All,

I found Dave Peterson's post saying there is no other way to check if a
worksheet is protected with a given password than try to unprotect it. I
wrote a sub for this purpose and it worked. I tried to recreate it in
function form and it also worked, although it made changes to the worksheet
(namely unprotected it) and functions don't do that in other cases. Finally I
tried to use it as a worksheet function (UDF), but it did not worked that way.

My questions:
1. Why does it work as a standard VBA function?
2. Why does not it work as an UDF? How could I make it work that way?

Thanks,
Stefi


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default is ws protected with a given password?

Functions return values to cells--they can't do this kind of thing. They can't
make changes to other cells or do most things that affect excel's environment
(like change the protection).



Stefi wrote:

Hi All,

I found Dave Peterson's post saying there is no other way to check if a
worksheet is protected with a given password than try to unprotect it. I
wrote a sub for this purpose and it worked. I tried to recreate it in
function form and it also worked, although it made changes to the worksheet
(namely unprotected it) and functions don't do that in other cases. Finally I
tried to use it as a worksheet function (UDF), but it did not worked that way.

My questions:
1. Why does it work as a standard VBA function?
2. Why does not it work as an UDF? How could I make it work that way?

Thanks,
Stefi


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,646
Default is ws protected with a given password?

Hi Dave,

I know that, but this function works when called from VBA and doesn't, as
you said, when used as an UDF. Is it normal that functions behave in
different ways in different environments?

Function pwvedett(ws As String)
If Worksheets(ws).ProtectScenarios Then
On Error Resume Next
Worksheets(ws).Unprotect Password:="pwd"
On Error GoTo 0
If Worksheets(ws).ProtectScenarios Then
pwvedett = False
Else
pwvedett = True
Worksheets(ws).Protect Password:="pwd", DrawingObjects:=True,
Contents:=True, Scenarios:=True
End If
Else
pwvedett = False
End If
End Function

Regards,
Stefi


Dave Peterson ezt *rta:

Functions return values to cells--they can't do this kind of thing. They can't
make changes to other cells or do most things that affect excel's environment
(like change the protection).



Stefi wrote:

Hi All,

I found Dave Peterson's post saying there is no other way to check if a
worksheet is protected with a given password than try to unprotect it. I
wrote a sub for this purpose and it worked. I tried to recreate it in
function form and it also worked, although it made changes to the worksheet
(namely unprotected it) and functions don't do that in other cases. Finally I
tried to use it as a worksheet function (UDF), but it did not worked that way.

My questions:
1. Why does it work as a standard VBA function?
2. Why does not it work as an UDF? How could I make it work that way?

Thanks,
Stefi


--

Dave Peterson

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default is ws protected with a given password?

Excel is very smart. It knows when your code was initiated by a formula in a
worksheet cell or from a call in a different subroutine.

It's normal.

Stefi wrote:

Hi Dave,

I know that, but this function works when called from VBA and doesn't, as
you said, when used as an UDF. Is it normal that functions behave in
different ways in different environments?

Function pwvedett(ws As String)
If Worksheets(ws).ProtectScenarios Then
On Error Resume Next
Worksheets(ws).Unprotect Password:="pwd"
On Error GoTo 0
If Worksheets(ws).ProtectScenarios Then
pwvedett = False
Else
pwvedett = True
Worksheets(ws).Protect Password:="pwd", DrawingObjects:=True,
Contents:=True, Scenarios:=True
End If
Else
pwvedett = False
End If
End Function

Regards,
Stefi

Dave Peterson ezt *rta:

Functions return values to cells--they can't do this kind of thing. They can't
make changes to other cells or do most things that affect excel's environment
(like change the protection).



Stefi wrote:

Hi All,

I found Dave Peterson's post saying there is no other way to check if a
worksheet is protected with a given password than try to unprotect it. I
wrote a sub for this purpose and it worked. I tried to recreate it in
function form and it also worked, although it made changes to the worksheet
(namely unprotected it) and functions don't do that in other cases. Finally I
tried to use it as a worksheet function (UDF), but it did not worked that way.

My questions:
1. Why does it work as a standard VBA function?
2. Why does not it work as an UDF? How could I make it work that way?

Thanks,
Stefi


--

Dave Peterson


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,646
Default is ws protected with a given password?

Thanks, Dave! Is there any place either in Excel Help or in technical
literature where such things are explicitly explained?

Regards,
Stefi


Dave Peterson ezt *rta:

Excel is very smart. It knows when your code was initiated by a formula in a
worksheet cell or from a call in a different subroutine.

It's normal.

Stefi wrote:

Hi Dave,

I know that, but this function works when called from VBA and doesn't, as
you said, when used as an UDF. Is it normal that functions behave in
different ways in different environments?

Function pwvedett(ws As String)
If Worksheets(ws).ProtectScenarios Then
On Error Resume Next
Worksheets(ws).Unprotect Password:="pwd"
On Error GoTo 0
If Worksheets(ws).ProtectScenarios Then
pwvedett = False
Else
pwvedett = True
Worksheets(ws).Protect Password:="pwd", DrawingObjects:=True,
Contents:=True, Scenarios:=True
End If
Else
pwvedett = False
End If
End Function

Regards,
Stefi

âžDave Peterson❠ezt Ã*rta:

Functions return values to cells--they can't do this kind of thing. They can't
make changes to other cells or do most things that affect excel's environment
(like change the protection).



Stefi wrote:

Hi All,

I found Dave Peterson's post saying there is no other way to check if a
worksheet is protected with a given password than try to unprotect it. I
wrote a sub for this purpose and it worked. I tried to recreate it in
function form and it also worked, although it made changes to the worksheet
(namely unprotected it) and functions don't do that in other cases. Finally I
tried to use it as a worksheet function (UDF), but it did not worked that way.

My questions:
1. Why does it work as a standard VBA function?
2. Why does not it work as an UDF? How could I make it work that way?

Thanks,
Stefi

--

Dave Peterson


--

Dave Peterson



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default is ws protected with a given password?

You could look at VBA's help.

http://msdn.microsoft.com
if you're looking for something specific.

Stefi wrote:

Thanks, Dave! Is there any place either in Excel Help or in technical
literature where such things are explicitly explained?

Regards,
Stefi

Dave Peterson ezt *rta:

Excel is very smart. It knows when your code was initiated by a formula in a
worksheet cell or from a call in a different subroutine.

It's normal.

Stefi wrote:

Hi Dave,

I know that, but this function works when called from VBA and doesn't, as
you said, when used as an UDF. Is it normal that functions behave in
different ways in different environments?

Function pwvedett(ws As String)
If Worksheets(ws).ProtectScenarios Then
On Error Resume Next
Worksheets(ws).Unprotect Password:="pwd"
On Error GoTo 0
If Worksheets(ws).ProtectScenarios Then
pwvedett = False
Else
pwvedett = True
Worksheets(ws).Protect Password:="pwd", DrawingObjects:=True,
Contents:=True, Scenarios:=True
End If
Else
pwvedett = False
End If
End Function

Regards,
Stefi

âžDave Peterson❠ezt Ã*rta:

Functions return values to cells--they can't do this kind of thing. They can't
make changes to other cells or do most things that affect excel's environment
(like change the protection).



Stefi wrote:

Hi All,

I found Dave Peterson's post saying there is no other way to check if a
worksheet is protected with a given password than try to unprotect it. I
wrote a sub for this purpose and it worked. I tried to recreate it in
function form and it also worked, although it made changes to the worksheet
(namely unprotected it) and functions don't do that in other cases. Finally I
tried to use it as a worksheet function (UDF), but it did not worked that way.

My questions:
1. Why does it work as a standard VBA function?
2. Why does not it work as an UDF? How could I make it work that way?

Thanks,
Stefi

--

Dave Peterson


--

Dave Peterson


--

Dave Peterson
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,646
Default is ws protected with a given password?

Thanks for you reply!
Stefi


Dave Peterson ezt *rta:

You could look at VBA's help.

http://msdn.microsoft.com
if you're looking for something specific.

Stefi wrote:

Thanks, Dave! Is there any place either in Excel Help or in technical
literature where such things are explicitly explained?

Regards,
Stefi

âžDave Peterson❠ezt Ã*rta:

Excel is very smart. It knows when your code was initiated by a formula in a
worksheet cell or from a call in a different subroutine.

It's normal.

Stefi wrote:

Hi Dave,

I know that, but this function works when called from VBA and doesn't, as
you said, when used as an UDF. Is it normal that functions behave in
different ways in different environments?

Function pwvedett(ws As String)
If Worksheets(ws).ProtectScenarios Then
On Error Resume Next
Worksheets(ws).Unprotect Password:="pwd"
On Error GoTo 0
If Worksheets(ws).ProtectScenarios Then
pwvedett = False
Else
pwvedett = True
Worksheets(ws).Protect Password:="pwd", DrawingObjects:=True,
Contents:=True, Scenarios:=True
End If
Else
pwvedett = False
End If
End Function

Regards,
Stefi

ââ¬Å¾Dave Petersonââ¬Â ezt ÃÂ*rta:

Functions return values to cells--they can't do this kind of thing. They can't
make changes to other cells or do most things that affect excel's environment
(like change the protection).



Stefi wrote:

Hi All,

I found Dave Peterson's post saying there is no other way to check if a
worksheet is protected with a given password than try to unprotect it. I
wrote a sub for this purpose and it worked. I tried to recreate it in
function form and it also worked, although it made changes to the worksheet
(namely unprotected it) and functions don't do that in other cases. Finally I
tried to use it as a worksheet function (UDF), but it did not worked that way.

My questions:
1. Why does it work as a standard VBA function?
2. Why does not it work as an UDF? How could I make it work that way?

Thanks,
Stefi

--

Dave Peterson


--

Dave Peterson


--

Dave Peterson

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
How to retrive password protected worksheet but forgot password? Laurie Excel Worksheet Functions 1 November 19th 09 09:42 PM
how to automate opening a password protected excel file? e.g. a .xls that has a password set in the security tab. Daniel Excel Worksheet Functions 0 June 23rd 05 11:56 PM
bypass password when update linking of password protected file Yan Excel Discussion (Misc queries) 1 February 7th 05 11:29 PM
Is .xls password protected. Tim Marsden Excel Programming 4 October 10th 04 07:17 AM
VBa, Password protected sheet fails to get unprotected with the same password Hans Rattink Excel Programming 3 July 28th 03 02:30 PM


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