Numbering error - page X of 1

S

Sanket

Hello all,

I had posted a question on Word Page layout regarding cutting and pasting
headers and footers into main part of the document.

While I have manages to do that - there remains one problem.
Instead of Page X of Y word gives me Page X of 1.

Eg: instead of Page 3 of 10 it shows Page 3 of 1.

Thanks for the help and suggestions.
 
S

Sanket

Hi,
I read the link you sent and have tried different things to overcome the
problem. It just does not go away. The problem is that the actual document
shows it correctly and the one which VBA creates does not.

It shows Page 1 of 1, Page 2 of 1, Page 3 of 1.......so on until the last
page.

I am pasting the code for the footer part of the program:

'###########^^^^^^^^^^^######################
'Process the document footer

'go back to the top
Selection.HomeKey Unit:=wdStory

'get the footer and turn it into text
If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
ActiveWindow.Panes(2).Close
End If

If ActiveWindow.ActivePane.View.Type = wdNormalView Or ActiveWindow. _
ActivePane.View.Type = wdOutlineView Then
ActiveWindow.ActivePane.View.Type = wdPageView
End If

ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader

If Selection.HeaderFooter.IsHeader = True Then
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter
Else
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
End If

'if we aren't inside the footer table go until down a line until we are.
Do
If Selection.Information(wdWithInTable) = False Then
Selection.Delete Unit:=wdCharacter, Count:=1 'delete the extraneous
carriage return
Selection.MoveDown Unit:=wdLine, Count:=1
Else: Exit Do
End If
Loop


' cut table from the footer

'^^^^%%%%%%^^^^^^^^^
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter
Selection.WholeStory
Selection.Cut
'^^^^%%%%%%^^^^^^^^^

'go back to the body of the document
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument

'do each page by going to the page after it and moving back up to the bottom
of 'the page we're going to process
If cntPages > 1 Then

'get the number of pages in the document again
PgNo = Selection.Information(wdActiveEndPageNumber)
PgNo = PgNo + 1

Do
Selection.GoTo What:=wdGoToPage, Which:=wdGoToAbsolute, Count:=PgNo
'go back up to the bottom of the previous page
Selection.MoveUp Unit:=wdLine, Count:=1
'preserve the font size that is in the table for the carriage returns
With Selection.Font
'Some code goes in here to preserve font size and attributes
End With

Selection.TypeParagraph
Selection.Paste
'update just in case
PgNo = PgNo + 1

Loop Until PgNo > cntPages
End If

'this is where one page documents will get the footer pasted in
Selection.EndKey Unit:=wdStory
Selection.TypeParagraph
Selection.Paste

'I'm at the bottom so select everything from here up, update the fields
(page numbers) and
' unlink them
Selection.WholeStory
Selection.Fields.Update
Selection.Fields.Unlink

'##########^^^^^^^^^^^^^^^^####################

Can someone point out where I am going wrong ??

Thanks a ton.

Sanket
 
S

Sanket

I am sorry - I forgot to mention I am using Word 2003 on Windows XP
Professional, Version 2002 with Service Pack 2.

Thanks,
Sanket
 
C

Charles Kenyon

I am cross-posting this in the vba.beginners newsgroup. The problem you are
having is with your code, not with Word (although Word may be complicating
things). It appears that what you are trying to do is convert a Word
document to a text file. The link Suzanne gave you is intended to fix the
problems with bugs in Word, not to fix bugs in your code. Sorry.

There are not separate footers for each page. Your code is going into
header/footer view. This is not especially useful. You would probably be
better off (and have faster code) if you use ranges instead.

You will, I think, need to get each page number, figure out which footer
applies to a particular page, get the text from that footer, and then put in
appropriate information. I'm surprised your code gives you the correct page
number.

I expect others who know far more about vba than do I will be able to help
you.
--
Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide


--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.
 
S

Sanket

Thank you Charles. I am not sure I understood all you said. But I am still
trying out a few things of my own.
I have just one footer int he document. I am converting a .RTF file to .DOC
file. I am copying the footer once and then pasting it on subsequent pages.

I also noticed a very strange thing. When I open the orginal .RTF document
(normally, by double clicking on the file- Not through VBA), the document
shows the page no's in the footer as Page 1 of 1, Page 2 of 1, Page 3 of 1,
Page 4 of 1..... and so on till the last page (Page 12 of 1).
It shows it this way for a few seconds (approx 10 secs) and then shows the
page no's in the normal way i.e. Page 1 of 12, Page 2 of 12, Page 3 of 12 and
so on.

I think my VBA program may be coming across this behaviour of Word and
somehow, I cant find any solution.

I am at my wits end.

Thanks again.
 
C

Charles Kenyon

Why are you not using the footer function in Word the way it is designed?
Why do you need new text on each page instead of a footer that repeats?

This will make your .doc file very hard to edit. It will make use of other
features like an Automatic Table of Contents problems, too. I'm not telling
you not to do it, just saying be sure you really want to do it. You are
programming against Word rather than with it. This is always hard.
--
Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide


--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.
 

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