title: Excel VBA Password Protection check
body: <p>I have a project in which I have to go over 1,000+ excel files in a folder, and see which ones are password protected and which ones aren't. In order to save time, I wrote a macro to do this, which is as follows:</p>
  <pre><code>    Sub CheckWbook()
       Dim Value As String, a As Single,  myfolder as string
       With Application.FileDialog(msoFileDialogFolderPicker)
          .Show
          myfolder = .SelectedItems(1) &amp; &quot;\&quot;
       End With
       Range(&quot;C4&quot;) = myfolder
       Range(&quot;B7:C&quot; &amp; Rows.Count) = &quot;&quot;
       a = 0
       Value = Dir(myfolder)
       Do Until Value = &quot;&quot;
          If Value = &quot;.&quot; Or Value = &quot;..&quot; Then
          Else
              If Right(Value, 3) = &quot;xls&quot; Or Right(Value, 4) = &quot;xlsx&quot; Or Right(Value, 4) = &quot;xlsm&quot; Then
                  On Error Resume Next
                  Workbooks.Open Filename:=myfolder &amp; Value, Password:=&quot;zzzzzzzzzzzz&quot;
                  If Err.Number &gt; 0 Then
                      Range(&quot;C7&quot;).Offset(a, 0).Value = &quot;Yes&quot;
                  End If
                  Workbooks(Value).Close False
                  On Error GoTo 0
                  Range(&quot;B7&quot;).Offset(a, 0).Value = Value
                  a = a + 1
               End If
  End If
  Value = Dir
  Loop
  End Sub
  </code></pre>
  <p>The problem I'm having is that the popup for the password is still present: it does not fill in the password. Any help would be highly appreciated. -A</p>
  <p><strong>Edit</strong>
  Changed the code a bit, and got past the error message, but now I'm getting stuck at the password popup, that stops the macro from completely working, despite the On Error Resume Next feature.</p>
  <p>Then, I came across this code that I thought could help:</p>
  <pre><code>    Option Explicit
  
  Public Sub ProcessBatch()
  
  Dim strFileName As String
  Dim strFilePath As String
  Dim oDoc As Document
  
  ' Set Directory for Batch Process
  strFilePath = &quot;C:\Test\&quot;
  
  ' Get Name of First .doc File from Directory
  strFileName = Dir$(strFilePath &amp; &quot;*.doc&quot;)
  
  
  While Len(strFileName) &lt;&gt; 0
  
      ' Set Error Handler
      On Error Resume Next
             
      ' Attempt to Open the Document
      Set oDoc = Documents.Open( _
                 FileName:=strFilePath &amp; strFileName, _
                 PasswordDocument:=&quot;?#nonsense@$&quot;)
     
      Select Case Err.Number
          Case 0
              ' Document was Successfully Opened
              Debug.Print strFileName &amp; &quot; was processed.&quot;
  
          Case 5408
              ' Document is Password-protected and was NOT Opened
              Debug.Print strFileName &amp; &quot; is password-protected &quot; &amp; _
                  &quot;and was NOT processed.&quot;
              ' Clear Error Object and Disable Error Handler
              Err.Clear
              On Error GoTo 0
              ' Get Next Document
              GoTo GetNextDoc
  
          Case Else
              ' Another Error Occurred
              MsgBox Err.Number &amp; &quot;:&quot; &amp; Err.Description
      End Select
     
      ' Disable Error Handler
      On Error GoTo 0
     
      '-------------------------------------
      '-------------------------------------
      '---Perform Action on Document Here---
      '-------------------------------------
      '-------------------------------------
     
      ' Close Document
      oDoc.Close
     
      ' Clear Object Variable
      Set oDoc = Nothing
     
  GetNextDoc:
     
      ' Get Next Document from Specified Directory
      strFileName = Dir$()
  
  Wend
  
  End Sub
  </code></pre>
  <p>but this fails to recognize the oDoc as a Document. Any ideas on how to get it working?</p>