JayM
Wed Aug 16 05:40:02 CDT 2006
DebsP
What a star you are!!
Many thanks for your help and guidance with this. I will look at for the
book you referred to. I have seen VB and VBA in a Nutshell and wondered
whether this was worth a delve into.
JayM
"debbieprobert via OfficeKB.com" wrote:
> Hi JayM
>
> In your ReprotectDocument routine, you're saying that if the document
> protection type is no protection at all then protect it - 'ActiveDocument.
> ProtectionType <> wdNoProtection'. The document will not be
>
> Your ReprotectDocument routine contains the line:
>
> 'If ActiveDocument.ProtectionType <> wdNoProtection' then
>
> This is saying
>
> 'If the document protection type is *not* no protection then' (forgive the
> English!)
>
> The document protection type at this stage *is* no protection as you removed
> it in your UnprotectDocument routine.
>
> What you want to be saying is:
>
> 'If ActiveDocument.ProtectionType = wdNoProtection then'
>
> However, you would then need to check the document to see if contained form
> fields and only reprotect those documents that do, otherwise you would end up
> protecting all documents.
>
> I believe your requirement is to deal with forms rather than all password
> protected documents. If so, this is the code I use to unprotect the form
> before any page setup commands are used. All our forms have the same
> password so I can pass this in the code (as strFormsPassword). You do not
> seem to have a password in which case I believe you can just use
> ActiveDocument.Unprotect without the password element.
>
> If the form was protected I set a Boolean variable to 'true' so that I know
> whether that form has to be re-protected later in the code. This variable is
> declared at Module level rather than within the Procedure. This means that
> all the Procedures within the Module can use it. A jargon free explanation
> (I hope) is that you simply put the Dim statement at the top of the page
> outside of the Sub area.
>
> Dim booWasProtected as Boolean 'Module level declaration of Boolean variable
>
> Sub UnProtect()
>
> 'if the document is protected for form fields
> If ActiveDocument.ProtectionType = wdAllowOnlyFormFields Then
> ActiveDocument.Unprotect strFormPassword
> 'this must be true otherwise the code would not have got this far
> booWasProtectedForm = True
> End If
>
> End Sub
>
> Sub Protect()
>
> If booWasProtectedForm Then
> ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True,
>
> Password:=strFormPassword
> End If
>
> End Sub
>
> I think there are a number of free online courses which you can find by
> hunting the web. Lots of places run hands-on courses depending upon where
> you are in the world. As to books, most can be pretty confusing for the non-
> programmer & it depends on how much you want to achieve. If you are largely
> customising the Word system & want to be able to do some fairly basic/medium
> level development to start with, you can do worse than something like "Word
> 2000 VBA Programmer's Reference". I expect there is a 2003 version now. I'm
> no programmer & I found this comprehensible. And don't be afraid of
> recording macros wherever you can - eventually you'll find shorter ways to do
> things but recorded macros can give you a head start.
>
> Hope that helps - & that the children are better :-)
>
> DebsP
>
>
>
>
> JayM wrote:
> >Forgot the code, so here it is
> >
> >Public Sub UNPROTECTDOCUMENT()
> >'Unprotect the Document
> >If ActiveDocument.ProtectionType <> wdNoProtection Then
> > ActiveDocument.Unprotect Password:=""
> >End If
> >End Sub
> >
> >Public Sub REPROTECTDOCUMENT()
> >'Protect the Document
> >If ActiveDocument.ProtectionType <> wdNoProtection Then
> > ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
> >End If
> >End Sub
> >
> >Sub PRINT_THIN_P()
> >' PRINT_THIN_P Macro
> >UNPROTECTDOCUMENT
> > With ActiveDocument.PageSetup
> > .FirstPageTray = wdPrinterPaperCassette
> > .OtherPagesTray = wdPrinterPaperCassette
> > End With
> > Application.PrintOut filename:="", Range:=wdPrintAllDocument,
> >Item:=wdPrintDocumentContent, Copies:=1, Pages:="",
> >PageType:=wdPrintAllPages, Collate:=True, Background:=True, PrintToFile:=False
> >REPROTECTDOCUMENT
> >End Sub
> >
> >> Hi JayM
> >>
> >[quoted text clipped - 31 lines]
> >> >> >
> >> >> >JayM
>
> --
> Message posted via OfficeKB.com
>
http://www.officekb.com/Uwe/Forums.aspx/word-programming/200608/1
>
>