PC Review


Reply
Thread Tools Rate Thread

Change Workbook Password

 
 
iperlovsky
Guest
Posts: n/a
 
      3rd Jul 2008
Does anyone know how to change the password using VBA for the entire workbook
from "x" to nothing - so that the user is not prompted to enter a password
next time the workbook is opened?

Thanks...
 
Reply With Quote
 
 
 
 
Gary Brown
Guest
Posts: n/a
 
      3rd Jul 2008
You'll need the password, but here's some code I've had that you can adapt.

'/============================================/
Private Sub ProtectPswd()
'template for unprotecting/protecting worksheet
Dim blnProtectContents As Boolean
Dim blnProtectDrawingObjects As Boolean
Dim blnProtectScenarios As Boolean
Dim strPassword As String

'set default for whether worksheet is protected or not
blnProtectContents = False
blnProtectDrawingObjects = False
blnProtectScenarios = False

'check if worksheet unprotected
' if it's protected, get various information
On Error Resume Next
If Application.ActiveSheet.ProtectContents = True Then
blnProtectContents = True
If Application.ActiveSheet.ProtectDrawingObjects = True Then
blnProtectDrawingObjects = True
End If
If Application.ActiveSheet.ProtectScenarios = True Then
blnProtectScenarios = True
End If
'protected so try password
strPassword = InputBox("Enter Password: " & vbCr & vbCr & _
"If there is no password, press ENTER." & vbCr & vbCr & _
"ONLY enter Password if source of this macro is TRUSTED!!!", _
"Password to Unprotect Worksheet...", "")
ActiveSheet.Unprotect password:=strPassword
'password didn't work - still not unprotected so stop process
If Application.ActiveSheet.ProtectContents = True Then
Exit Sub
End If
End If
On Error GoTo 0

' ++++++++++++++++++++++ put coding here +++++++++++++++++

'set worksheet back to original protected/unprotected state
On Error Resume Next
ActiveSheet.Protect password:=strPassword, _
DrawingObjects:=blnProtectDrawingObjects, _
Contents:=blnProtectContents, Scenarios:=blnProtectScenarios

End Sub
'/============================================/

--
Hope this helps.
If this post was helpfull, please remember to click on the ''''YES''''
button at the bottom of the screen.
Thanks,
Gary Brown


"iperlovsky" wrote:

> Does anyone know how to change the password using VBA for the entire workbook
> from "x" to nothing - so that the user is not prompted to enter a password
> next time the workbook is opened?
>
> Thanks...

 
Reply With Quote
 
iperlovsky
Guest
Posts: n/a
 
      3rd Jul 2008
Is this for a workbook or a worksheet. It looks like it is for a worksheet.

"Gary Brown" wrote:

> You'll need the password, but here's some code I've had that you can adapt.
>
> '/============================================/
> Private Sub ProtectPswd()
> 'template for unprotecting/protecting worksheet
> Dim blnProtectContents As Boolean
> Dim blnProtectDrawingObjects As Boolean
> Dim blnProtectScenarios As Boolean
> Dim strPassword As String
>
> 'set default for whether worksheet is protected or not
> blnProtectContents = False
> blnProtectDrawingObjects = False
> blnProtectScenarios = False
>
> 'check if worksheet unprotected
> ' if it's protected, get various information
> On Error Resume Next
> If Application.ActiveSheet.ProtectContents = True Then
> blnProtectContents = True
> If Application.ActiveSheet.ProtectDrawingObjects = True Then
> blnProtectDrawingObjects = True
> End If
> If Application.ActiveSheet.ProtectScenarios = True Then
> blnProtectScenarios = True
> End If
> 'protected so try password
> strPassword = InputBox("Enter Password: " & vbCr & vbCr & _
> "If there is no password, press ENTER." & vbCr & vbCr & _
> "ONLY enter Password if source of this macro is TRUSTED!!!", _
> "Password to Unprotect Worksheet...", "")
> ActiveSheet.Unprotect password:=strPassword
> 'password didn't work - still not unprotected so stop process
> If Application.ActiveSheet.ProtectContents = True Then
> Exit Sub
> End If
> End If
> On Error GoTo 0
>
> ' ++++++++++++++++++++++ put coding here +++++++++++++++++
>
> 'set worksheet back to original protected/unprotected state
> On Error Resume Next
> ActiveSheet.Protect password:=strPassword, _
> DrawingObjects:=blnProtectDrawingObjects, _
> Contents:=blnProtectContents, Scenarios:=blnProtectScenarios
>
> End Sub
> '/============================================/
>
> --
> Hope this helps.
> If this post was helpfull, please remember to click on the ''''YES''''
> button at the bottom of the screen.
> Thanks,
> Gary Brown
>
>
> "iperlovsky" wrote:
>
> > Does anyone know how to change the password using VBA for the entire workbook
> > from "x" to nothing - so that the user is not prompted to enter a password
> > next time the workbook is opened?
> >
> > Thanks...

 
Reply With Quote
 
Gary Brown
Guest
Posts: n/a
 
      3rd Jul 2008
Sorry, misread the post. The code IS for a worksheet.
--
Gary Brown


"iperlovsky" wrote:

> Is this for a workbook or a worksheet. It looks like it is for a worksheet.
>
> "Gary Brown" wrote:
>
> > You'll need the password, but here's some code I've had that you can adapt.
> >
> > '/============================================/
> > Private Sub ProtectPswd()
> > 'template for unprotecting/protecting worksheet
> > Dim blnProtectContents As Boolean
> > Dim blnProtectDrawingObjects As Boolean
> > Dim blnProtectScenarios As Boolean
> > Dim strPassword As String
> >
> > 'set default for whether worksheet is protected or not
> > blnProtectContents = False
> > blnProtectDrawingObjects = False
> > blnProtectScenarios = False
> >
> > 'check if worksheet unprotected
> > ' if it's protected, get various information
> > On Error Resume Next
> > If Application.ActiveSheet.ProtectContents = True Then
> > blnProtectContents = True
> > If Application.ActiveSheet.ProtectDrawingObjects = True Then
> > blnProtectDrawingObjects = True
> > End If
> > If Application.ActiveSheet.ProtectScenarios = True Then
> > blnProtectScenarios = True
> > End If
> > 'protected so try password
> > strPassword = InputBox("Enter Password: " & vbCr & vbCr & _
> > "If there is no password, press ENTER." & vbCr & vbCr & _
> > "ONLY enter Password if source of this macro is TRUSTED!!!", _
> > "Password to Unprotect Worksheet...", "")
> > ActiveSheet.Unprotect password:=strPassword
> > 'password didn't work - still not unprotected so stop process
> > If Application.ActiveSheet.ProtectContents = True Then
> > Exit Sub
> > End If
> > End If
> > On Error GoTo 0
> >
> > ' ++++++++++++++++++++++ put coding here +++++++++++++++++
> >
> > 'set worksheet back to original protected/unprotected state
> > On Error Resume Next
> > ActiveSheet.Protect password:=strPassword, _
> > DrawingObjects:=blnProtectDrawingObjects, _
> > Contents:=blnProtectContents, Scenarios:=blnProtectScenarios
> >
> > End Sub
> > '/============================================/
> >
> > --
> > Hope this helps.
> > If this post was helpfull, please remember to click on the ''''YES''''
> > button at the bottom of the screen.
> > Thanks,
> > Gary Brown
> >
> >
> > "iperlovsky" wrote:
> >
> > > Does anyone know how to change the password using VBA for the entire workbook
> > > from "x" to nothing - so that the user is not prompted to enter a password
> > > next time the workbook is opened?
> > >
> > > Thanks...

 
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
Change a users password without knowing the old password nor the answer to the password question AAaron123 Microsoft ASP .NET 1 16th Jan 2009 02:56 PM
change workbook password =?Utf-8?B?bmVlcmFq?= Microsoft Excel Misc 1 20th Sep 2005 06:18 PM
Multiple workbook user's with Master workbook - all password protected Yvon Microsoft Excel Misc 2 30th Mar 2005 01:34 PM
how do I open excel workbook If i forget my workbook password =?Utf-8?B?YXY4cmFydA==?= Microsoft Excel Misc 1 28th Oct 2004 07:18 AM
Open a password protected excel workbook from second workbook to fetch data using dynamic connection kaustav choudhury Microsoft Excel Programming 2 3rd Apr 2004 06:18 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:35 AM.