0
votes

I am automating the creation of MS Word 2007 documents from MS Access 2007.

The word documents are templates (.dotx). They are password protected.

Using VBA, I need to pass through a password when I open the template. However, using my current method, I can't see any option of doing this. If I use the documents.open method, there is a password option however when I open the template this way, it opens the live template and not a copy.

Below is my current code, any help would be appreciated.

'Pass in a path and open a word doc
Sub openWordTemplate(sDocumentPath As String, sDocumentName As String)

Dim appWord As Word.Application
Dim appDocument As Word.Document

Set appWord = New Word.Application
appWord.Visible = False

'Commented out as this opens the live doc and not a copy of the template.
'Set appDocument = appWord.Documents.Open(sDocumentPath & sDocumentName, , , , TEMPLATE_PWD)


'Open the template. But where can I pass in the password?
Set appDocument = appWord.Documents.Add(sDocumentPath & sDocumentName)


End Sub
1
I would say take a read through this, you might need to modify your code a little but it seems like this is the best resource for how to do what you are looking for. social.msdn.microsoft.com/Forums/office/en-US/… Sorry I can't be more specific, I don't have a ton experience with opening password protected word files, hopefully this is enough to point you in the right direction thought :-) - Newd

1 Answers

0
votes

Documents.Add? Not sure about that, I think you need Documents.Open instead.

appWord.Documents.Open(sDocumentPath & sDocumentName), 
passwordtemplate:="YourPassword", Visible:=True

I know I have this in one of my apps and it works:

Word.Application.Documents.Open ("C:\ TEMPLATES\CONTRACT VARIATION .dot"),
passwordtemplate:="checkopen", Visible:=True