
Signature
Suzanne S. Barnhill
Microsoft MVP (Word)
Words into Type
Fairhope, Alabama USA
Word MVP FAQ site: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
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
> See http://word.mvps.org/FAQs/AppErrors/PageXofY.htm
>
[quoted text clipped - 9 lines]
> >
> > Thanks for the help and suggestions.
Sanket - 16 Mar 2006 18:07 GMT
I am sorry - I forgot to mention I am using Word 2003 on Windows XP
Professional, Version 2002 with Service Pack 2.
Thanks,
Sanket
> Hi,
> I read the link you sent and have tried different things to overcome the
[quoted text clipped - 109 lines]
> > >
> > > Thanks for the help and suggestions.
Charles Kenyon - 16 Mar 2006 18:56 GMT
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.

Signature
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
See also the MVP FAQ: http://word.mvps.org/FAQs/ which is awesome!
--------- --------- --------- --------- --------- ---------
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.
> Hi,
> I read the link you sent and have tried different things to overcome the
[quoted text clipped - 118 lines]
> Thanks,
> Sanket
Sanket - 16 Mar 2006 20:05 GMT
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.
> 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
[quoted text clipped - 13 lines]
> I expect others who know far more about vba than do I will be able to help
> you.
Charles Kenyon - 16 Mar 2006 20:25 GMT
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.

Signature
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
See also the MVP FAQ: http://word.mvps.org/FAQs/ which is awesome!
--------- --------- --------- --------- --------- ---------
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.
> Thank you Charles. I am not sure I understood all you said. But I am still
> trying out a few things of my own.
[quoted text clipped - 42 lines]
>> help
>> you.