Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 13th, 2012  |  syntax: None  |  size: 0.69 KB  |  hits: 23  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. How can I see if a Word-file is password-protected?
  2. // Open the document...
  3. this.document = wordApplication.Documents.Open(
  4.    ref inputFile, ref confirmConversions, ref readOnly, ref missing,
  5.    ref missing, ref missing, ref missing, ref missing,
  6.    ref missing, ref missing, ref missing, ref visible,
  7.    ref missing, ref missing, ref missing, ref missing);
  8.        
  9. Sub MyMacro()
  10.  
  11. Dim oDoc As Document
  12.  
  13. On Error Resume Next
  14.  
  15. Set oDoc = Documents.Open(FileName:="C:MyFile.doc", PasswordDocument:=password)
  16. Select Case Err.Number
  17.     Case 0
  18.      Debug.Print "File was processed."
  19.  
  20.     Case 5408
  21.      'Debug.Print "Wrong password!"
  22.  
  23.     Case Else
  24.      MsgBox Err.Number & ":" & Err.Description
  25. End Select