Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default Error Trap for bypassing Password Protection

I have a macro where I am cycling through all of the *.XLS files in a
directory, but I have to segregate any file that has a non-blank
password out of that directory.

My current code keeps stopping with 1004-Runtime Errors for an invalid
password.
Ideally, I would like it to detect if a password is present, and if it
is blank, unprotect it; if not, then move the file to the specified
directory.

My code works fine with regard to the file-open password, but not with
any other protection scheme.

'===========================CODE

If ActiveWorkbook.MultiUserEditing = True Then
ActiveWorkbook.UnprotectSharing
ActiveWorkbook.ExclusiveAccess
End If

If ActiveWorkbook.ProtectStructure = True Then
If Err.Number < 0 Then GoTo HAS_WORKBOOK_LEVEL_PASSWORDS
ActiveWorkbook.Unprotect Password:=""
GoTo HAS_BLANK_WORKBOOK_LEVEL_PASSWORDS

HAS_WORKBOOK_LEVEL_PASSWORDS:

i = i + 1 '===File Counter for Directory
ActiveWorkbook.Close
Name temp_name As PWP_DIR_AND_FILE
GoTo Begin
Err.Clear
End If

HAS_BLANK_WORKBOOK_LEVEL_PASSWORDS:
Err.Clear



If ActiveWorkbook.ProtectWindows = True Then
On Error GoTo HAS_WORKBOOK_WINDOW_LEVEL_PASSWORDS
ActiveWorkbook.Unprotect Password:=""
GoTo HAS_BLANK_WORKBOOK_WINDOW_LEVEL_PASSWORDS
HAS_WORKBOOK_WINDOW_LEVEL_PASSWORDS:
i = i + 1
ActiveWorkbook.Close
Name temp_name As PWP_DIR_AND_FILE
GoTo Begin
Err.Clear
End If
HAS_BLANK_WORKBOOK_WINDOW_LEVEL_PASSWORDS:
Err.Clear



If ActiveSheet.ProtectContents = True Then
If Err.Number < 0 Then GoTo HAS_SHEET_PASSWORDS
ActiveSheet.Unprotect Password:=""
GoTo HAS_BLANK_SHEET_PASSWORD
HAS_SHEET_PASSWORDS:
i = i + 1
ActiveWorkbook.Close
Name temp_name As PWP_DIR_AND_FILE
Err.Clear
GoTo Begin
End If

HAS_BLANK_SHEET_PASSWORD:
Err.Clear

'==============================END CODE=====

I have been prowling the forums for an acceptable answer, but none has
availed itself as of yet.

Any help would be appreciated. Thanks!

~Arawn
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
Error: Sharing Workbook w/password protection Jeff Wollschlager Excel Discussion (Misc queries) 0 May 13th 09 04:29 PM
Error when save as CSV with VBA password protection on [email protected] Excel Discussion (Misc queries) 0 August 1st 06 10:50 PM
Bypassing password Fred Excel Programming 1 December 16th 03 12:35 PM
error trap Rhonda[_3_] Excel Programming 2 October 22nd 03 07:07 PM


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