Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
Word
application.errors
conversions
docmanagement
drawing.graphics
formatting.longdocs
international
internet.assistant
mail
mailmerge.fields
menustoolbars
newusers
numbering
oleinterop
pagelayout
printingfonts
setup.networking
spelling.grammar
tables
vba.addins
vba.beginners
vba.customization
vba.general
vba.userforms
web.authoring
word6-7macros
word97vba
  
 
date: Fri, 26 Sep 2008 07:43:01 -0700,    group: microsoft.public.word.vba.general        back       


can't uprotect with Document_Open   
I posted this once, but it was messy and I kept replying to myself, so I'm 
just marking that one as answered and rewriting.

I have a Word document with Form Field protection.  It has code for both 
Document_Close and Document_Open.

Both use this to turn off and turn back on the protection:

If ActiveDocument.ProtectionType <> wdNoProtection Then
    ActiveDocument.Unprotect Password:=""
End If

...and then...

ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True, 
Password:=""

In between these statements, I have some code that attempts to change the 
font of some form fields, but for some reason, the Document_Open sub 
procedure doesn't work, specifically because it says that form protection is 
on, but only during the actual open event.  If I manually run it after the 
document is already open, it works fine.  Using message boxes, I was able to 
determine that the Document_Open procedure is actually running when I open 
the document, but it acts as if it's ignoring the piece of code that 
unprotects the form.

What could be the reason for this?  It is really odd that this unprotect 
code only fails during the open event, and by fail I don't mean it returns an 
error (the code attempting to change the fields complain about protection 
still being on), but it just seems like it skips right over it.

Any ideas?

Thanks!
date: Fri, 26 Sep 2008 07:43:01 -0700   author:   kill_beast

Re: can't uprotect with Document_Open   
Hi =?Utf-8?B?a2lsbF9iZWFzdA==?=,

Is it possible that, at this point in time, ActiveDocument is not the document 
opening, but another document in the Word application? Have you tried a MsgBox 
ActiveDocument.Name to check?

How about if you use Thisdocument, instead (although that won't do what you want 
if this is a template)?

> I posted this once, but it was messy and I kept replying to myself, so I'm 
> just marking that one as answered and rewriting.
>  
> I have a Word document with Form Field protection.  It has code for both 
> Document_Close and Document_Open.
>  
> Both use this to turn off and turn back on the protection:
>  
> If ActiveDocument.ProtectionType <> wdNoProtection Then
>     ActiveDocument.Unprotect Password:=""
> End If
>  
> ....and then...
>  
> ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True, 
> Password:=""
>  
> In between these statements, I have some code that attempts to change the 
> font of some form fields, but for some reason, the Document_Open sub 
> procedure doesn't work, specifically because it says that form protection is 
> on, but only during the actual open event.  If I manually run it after the 
> document is already open, it works fine.  Using message boxes, I was able to 
> determine that the Document_Open procedure is actually running when I open 
> the document, but it acts as if it's ignoring the piece of code that 
> unprotects the form.
>  
> What could be the reason for this?  It is really odd that this unprotect 
> code only fails during the open event, and by fail I don't mean it returns an 
> error (the code attempting to change the fields complain about protection 
> still being on), but it just seems like it skips right over it.
>

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply 
in the newsgroup and not by e-mail :-)
date: Tue, 30 Sep 2008 20:51:00 +0200   author:   Cindy M.

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us