Save a password protected word doc as a pdf

Soniaski

Registered User.
Local time
Today, 13:09
Joined
Jun 20, 2012
Messages
21
I've been researching this for quite a while and can't find a solution. I'm opening a password protected word document and trying to save it in a pdf format. I can do this easily on a non-password protected document:

Dim objWord As Word.Document
Set objWord = GetObject("c:\temp\test.doc", "Word.Document")
objWord.Application.Visible = True
objWord.SaveAs "c:\temp\test.pdf", 17
objWord.Application.Quit

The trouble begins when I add a password. I couldn't find a way to open the password protected word document using GetObject, so I changed the code as follows:

Set objWord = CreateObject("Word.Application")
objWord.Documents.Open "c:\temp\test.doc", , , , PasswordDocument:="test"
objWord.Visible = True
objWord.Activate
objWord.Documents.Save

The code above works perfect fine if I want to just save the document in it's current state and not convert to a pdf file. Honestly, I can't even figure out how to do a objword.documents.saveas for the code above. Everything I try comes back with errors. Too many to mention :eek: .

Does anyone have any insight on this issue?
 
Hmm.. You need to Declare the object as Word.Application, rather than Word.Document.. The following seems to work..
Code:
Public Sub testMe()
    Dim objWord As Word.Application
    Set objWord = New Word.Application
    objWord.Documents.Open "c:\temp\test.doc", PasswordDocument:="test"
    objWord.Visible = True
    objWord.ActiveDocument.SaveAs2 "c:\temp\test.doc.pdf", wdExportFormatPDF
    Set objWord = Nothing
End Sub
 
Thank you Paul. I tried your suggestion and I come up with the error ":Runtime error 438. Object doesn't support this property or method" when attempting to do the saveas2.

WooHoo! Just tried it changing the SaveAs2 to SaveAs and it worked!

Thank you very much. I'm going out to research SaveAs2 so I can get a better understanding. I appreciate your help.
 

Users who are viewing this thread

Back
Top Bottom