PDA

View Full Version : Solved: unprotect sections of word document with excel



rob0923
08-26-2009, 05:36 PM
Hi,

I have a program that pushes values from Excel to a Word template. Part of the word template has a protected section (section2) and I need to somehow disable the protection with the excel vba and once everything has been completed to put the password back on the section.

I've been trying to search for this, but I can only find how to protect the whole document.

Benzadeus
09-01-2009, 12:09 PM
Sub Proccess_Word_Document()

Const strPassword As String = "password"

Dim wdApp As Word.Application
Dim wdDoc As Word.Document

Set wdApp = GetObject(, "Word.Application")
Set wdDoc = wdApp.Documents(1)

wdDoc.Unprotect strPassword
'Do actions
wdDoc.Protect Password:=strPassword, Type:=wdAllowOnlyReading

Set wdDoc = Nothing
Set wdApp = Nothing

End Sub