Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 50
Default Change Workbook Password

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...
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 209
Default Change Workbook Password

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...

  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 50
Default Change Workbook Password

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...

  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 209
Default Change Workbook Password

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
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
need to open my workbook not asking for password so i can do so Christine[_2_] Excel Discussion (Misc queries) 0 October 4th 07 10:31 PM
workbook password recovery roadrunner Excel Discussion (Misc queries) 2 October 6th 06 08:03 PM
change workbook password neeraj Excel Discussion (Misc queries) 1 September 20th 05 06:18 PM
Workbook Password Kevin Excel Discussion (Misc queries) 1 April 15th 05 11:53 AM
Multiple workbook user's with Master workbook - all password protected Yvon Excel Discussion (Misc queries) 2 March 30th 05 01:34 PM


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