Shawn Miller
New Member
Hello,
I am trying to run a macro that loops through files in a folder path and reports Yes/No if it has a write protect password. The script below works, but a user has to wait for each file to open and hit "esc" on the password dialog box if the file has a write protect password. I tried modifying the section that says Password:="zzzzzzzzzzzz" to be WriteResPassword:="zzzzzzzzzz" and when I did this the macro looped through without user interaction BUT it simply reported all files having a write protect password, even those some files did NOT have a write protect password.
Any suggestions on how to modify this or is there an easier way to check?
>>> use code - tags as written in Forum Rules <<<
I am trying to run a macro that loops through files in a folder path and reports Yes/No if it has a write protect password. The script below works, but a user has to wait for each file to open and hit "esc" on the password dialog box if the file has a write protect password. I tried modifying the section that says Password:="zzzzzzzzzzzz" to be WriteResPassword:="zzzzzzzzzz" and when I did this the macro looped through without user interaction BUT it simply reported all files having a write protect password, even those some files did NOT have a write protect password.
Any suggestions on how to modify this or is there an easier way to check?
>>> use code - tags as written in Forum Rules <<<
Code:
Sub CheckWbook()
Dim Value As String, a As Single
With Application.FileDialog(msoFileDialogFolderPicker)
.Show
myfolder = .SelectedItems(1) & "\"
End With
Range("C4") = myfolder
Range("B7:C" & Rows.Count) = ""
a = 0
Value = Dir(myfolder)
Do Until Value = ""
If Value = "." Or Value = ".." Then
Else
If Right(Value, 3) = "xls" Or Right(Value, 4) = "xlsx" Or Right(Value, 4) = "xlsm" Then
On Error Resume Next
Workbooks.Open Filename:=myfolder & Value, Password:="zzzzzzzzzzzz"
If Err.Number > 0 Then
Range("C7").Offset(a, 0).Value = "Yes"
End If
Workbooks(Value).Close False
On Error GoTo 0
Range("B7").Offset(a, 0).Value = Value
a = a + 1
End If
End If
Value = Dir
Loop
End Sub
Last edited by a moderator: