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
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.