Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / November 2006

Tip: Looking for answers? Try searching our database.

Unprotect and protect word document

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
anders.carl.karlsson@gmail.com - 10 Nov 2006 09:12 GMT
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
Doug Robbins - Word MVP - 10 Nov 2006 12:20 GMT
See http://support.microsoft.com/kb/286841/en-us

Signature

Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

> Hi,
>
[quoted text clipped - 45 lines]
>
> /ANders

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.