Unprotect and protect word document

  • Thread starter anders.carl.karlsson
  • Start date
A

anders.carl.karlsson

Hi,

I have a slight problem with unprotecting and protecting a
worddocument.

I have a word document with a lot of mail merge fields, drop-downs and
tabbing. In order to make the tabs and drop-downs work the document
needs to be protected.

When I fill the document programmatically in VBS I need to unprotect
the document, works fine, and then protect it after the mailmerging is
done.

The problem is that I cannot protect it and the drop-downs and tabbing
doesn't work.

This is probably an easy fix but I haven't got a solution yet.

My code is:

Dim objWord
set objWord = CreateObject("Word.Application")

Dim oDoc
Set oDoc = objWord.ActiveDocument

Dim lcProtectionType, llProtectDoc
llProtectDoc = false
'if the document is protected then unprotect it so we can read it
If oDoc.ProtectionType <> -1 Then
lcProtectionType = oDoc.ProtectionType 'get the type of protection

llProtectDoc = True 'set a flag so we know we need to reapply the
protection
oDoc.UnProtect("word") 'unprotect the document

End If

-- Mail Merging Code --
* Some code *
-- End Mail Merging Code --

if (llProtectDoc) then
objWord.Protect lcProtectionType,,"word"
end if

I would appreciate some help in this matter.

/ANders
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top