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 / July 2007

Tip: Looking for answers? Try searching our database.

Current page number in Protected document don't work

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
lojze066 - 04 Jul 2007 10:18 GMT
I have the following problem with Current page number which appears in Word
2000
My users unfortunately use Word 2000 (9.0.4402 SR-1)

When I protect document programmatically with following code

Const wdAllowOnlyComments=1
WordObj.ActiveDocument.Protect wdAllowOnlyComments, False, "PASSWORD"

the current page number is always 1.

(on all pages is 1 of 4)

The problem exist even if I do everything manually in Word so probably this
is a Bug or something.

Does anybody have an solution how to correct this problem.

Thank you

Lojze
Russ - 05 Jul 2007 00:13 GMT
Lojze,
So are you saying that if you comment out those two lines of code with an
apostrophe, then the page numbers are correct when you rerun the code?
And what code are you using to get the page numbers?

> I have the following problem with Current page number which appears in Word
> 2000
[quoted text clipped - 17 lines]
>
> Lojze

Signature

Russ

drsmN0SPAMikleAThotmailD0Tcom.INVALID

lojze066 - 05 Jul 2007 09:58 GMT
Yes, if I don't protect document, the page numbering is correct.
I have a Word template in which I have footer with page numbering. For page
numbering I use already prepared Word Header/footer button Insert page number
which inserts Field Page.

Maybe is the problem because this field Page probably uses formula for
calculating page number and when document is protected the formula could not
be run?

Regards
Lojze

> Lojze,
> So are you saying that if you comment out those two lines of code with an
[quoted text clipped - 22 lines]
> >
> > Lojze
Russ - 05 Jul 2007 11:07 GMT
Lojze,

Add this subroutine to your project, then use:
Call UpdateAllFields
Just before you protect you document.

Sub UpdateAllFields()
Dim oStory As Range
 For Each oStory In ActiveDocument.StoryRanges
   oStory.Fields.Update
   If oStory.StoryType <> wdMainTextStory Then
     While Not (oStory.NextStoryRange Is Nothing)
       Set oStory = oStory.NextStoryRange
       oStory.Fields.Update
     Wend
   End If
 Next oStory
 Set oStory = Nothing
End Sub

> Yes, if I don't protect document, the page numbering is correct.
> I have a Word template in which I have footer with page numbering. For page
[quoted text clipped - 34 lines]
>>>
>>> Lojze

Signature

Russ

drsmN0SPAMikleAThotmailD0Tcom.INVALID

lojze066 - 05 Jul 2007 13:16 GMT
I use Lotus script (Lotus notes appliaction) so I change your sub to:
Sub UpdateAllFields()
    Const wdMainTextStory = 1
    Forall oStory In WordDoc.StoryRanges
        oStory.Fields.Update
        If oStory.StoryType <> wdMainTextStory Then
            While Not (oStory.NextStoryRange Is Nothing)
                Set oStory = oStory.NextStoryRange
                oStory.Fields.Update
            Wend
        End If
    End Forall
End Sub

and I call it like that:

Call UpdateAllFields
WordDoc.Protect wdAllowOnlyComments, False, "PASSWORD"

Now after protection I got on all pages 4 of 4.

Regards
Lojze

> Lojze,
>
[quoted text clipped - 54 lines]
> >>>
> >>> Lojze
Russ - 07 Jul 2007 00:44 GMT
Lojze,
I don't know what Lotus script (Lotus notes application) brings into the
mix.
See comment below.

> I use Lotus script (Lotus notes appliaction) so I change your sub to:
> Sub UpdateAllFields()
[quoted text clipped - 16 lines]
>
> Now after protection I got on all pages 4 of 4.
Looks like your initial problem is that you are using the wrong fields.
When you go into header of footer in Word, there is a AutoText list entry on
the toolbar you can use: that produces text like this:
Page { PAGE } of { NUMPAGES }
When you go into footer or header and toggle between the code and results
with keys ALT/F9, what do you see.
You can edit the very first field to say { PAGE }, if it doesn't, and
normally all the subsequent similar fields in the document will change, too.

Things get more complicated when you want the numbering to restart in each
section, etc.

> Regards
> Lojze
[quoted text clipped - 60 lines]
>>>>>
>>>>> Lojze

Signature

Russ

drsmN0SPAMikleAThotmailD0Tcom.INVALID

 
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.