Current page number in Protected document don't work

L

lojze066

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
 
R

Russ

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?
 
L

lojze066

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
 
R

Russ

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
 
L

lojze066

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
 
R

Russ

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()
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.
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.
 

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