Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Request password during Protect macro


Hi.
I have a macro that unprotects and protects a Sheet & Workbook, but I
want excel to prompt the user to provide the password as if they had
selected protect/unprotect from the menu. How do I do this?
Thanks for any help.
Regards
Gavin


------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~View and post usenet messages directly from http://www.ExcelForum.com/

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default Request password during Protect macro

Hi Gavin,

You could use something like

Sub Pwd()
Dim Pwd, Res
Pwd = "abracadabra"
Res = InputBox("Please Enter Password")
If Res < Pwd Then Exit Sub
End Sub

You can either call this Sub from your Unprotect macr or includenthe code
within the macro.

HTH

Don
--

"Gavin" wrote in message
...

Hi.
I have a macro that unprotects and protects a Sheet & Workbook, but I
want excel to prompt the user to provide the password as if they had
selected protect/unprotect from the menu. How do I do this?
Thanks for any help.
Regards
Gavin


------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~View and post usenet messages directly from http://www.ExcelForum.com/



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 493
Default Request password during Protect macro

One way:

Dim pWord As Variant
Dim wkSht As Worksheet
Set wkSht = ActiveSheet ' for testing
With wkSht
If .ProtectContents Then
Do
pWord = Application.InputBox( _
Prompt:="Password: ", _
Title:="Unprotect Sheet", _
Type:=2)
If pWord = False Then Exit Sub 'User clicked Cancel
On Error Resume Next
wkSht.Unprotect pWord
On Error GoTo 0
Loop Until .ProtectContents = False
End If
End With


In article ,
Gavin wrote:

I have a macro that unprotects and protects a Sheet & Workbook, but I
want excel to prompt the user to provide the password as if they had
selected protect/unprotect from the menu. How do I do this?
Thanks for any help.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Request password during Protect macro


Thanks for the help.

I know that what you suggest would work, but I wasn't wanting to have
to use Inputboxes. They don't have character masking and I didn't want
to get involved in having to confirm the input of a PW when switching
protection on.

I was hoping that Excel would do that that for me like when you turn
protection on and off through the menus.

In fact, can I not trigger menu actions from VBA code?

Thanks again
Gavin


------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~View and post usenet messages directly from http://www.ExcelForum.com/

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 493
Default Request password during Protect macro

Use a user form. Userform Textboxes have character masking (set the
PasswordChar property to the character you want).


In article ,
Gavin wrote:

Thanks for the help.

I know that what you suggest would work, but I wasn't wanting to have
to use Inputboxes. They don't have character masking and I didn't want
to get involved in having to confirm the input of a PW when switching
protection on.

I was hoping that Excel would do that that for me like when you turn
protection on and off through the menus.

In fact, can I not trigger menu actions from VBA code?



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Request password during Protect macro


At the risk of sounding like an idiot...
I've created a userform for the use to enter a password, but how do
send the password back from the text box to my macro?


------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~View and post usenet messages directly from http://www.ExcelForum.com/

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Request password during Protect macro


Got it! The Dialog boxes toggle protection on and off. If I don't sen
any agruments then if protection was on, excel asks for a password an
thurns protection off. If protection was off, then excel asks for
password, asks for confirmation of the password, and then turn
protection on.
Fantastic :

-----------------------------------------------
~~ Message posted from http://www.ExcelTip.com
~~View and post usenet messages directly from http://www.ExcelForum.com

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
Macro to allow auto filter after running password protect Roady Excel Discussion (Misc queries) 1 July 17th 08 06:34 PM
Macro to re-protect sheet w/ original password after pasting valuesin new book [email protected] Excel Worksheet Functions 1 June 4th 08 04:27 PM
Password Protect Macro - Compile Error Teddy-B Excel Discussion (Misc queries) 1 January 23rd 08 02:50 AM
Code to protect/unprotect a sheet using a macro with password FredH Excel Discussion (Misc queries) 5 October 23rd 07 04:49 PM
Add protect worksheet password in macro Kelly Excel Worksheet Functions 1 January 10th 06 02:08 AM


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