Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 12-06-2012, 09:19 AM
eslight eslight is offline Macro to Add Text and Page Number to Top of Each Page Within Text Windows 7 64bit Macro to Add Text and Page Number to Top of Each Page Within Text Office 2010 64bit
Novice
Macro to Add Text and Page Number to Top of Each Page Within Text
 
Join Date: Dec 2012
Posts: 7
eslight is on a distinguished road
Default Macro to Add Text and Page Number to Top of Each Page Within Text

I need to insert a bit of text and the page number into the body of the document at the exact spot where the top of each page starts (in the body, not the header), so it would look like **P[page number]. I need the macro to start at the last page and work towards the first page, so that the newly added text does not change where the original page number would have started. When it is done, I want a document that contains these textual page notations, even if the macro shifted the page numbering when it added the new text. I do not care if the newly added text splits a word. Any ideas? Thanks!
Reply With Quote
  #2  
Old 12-06-2012, 08:23 PM
macropod's Avatar
macropod macropod is offline Macro to Add Text and Page Number to Top of Each Page Within Text Windows 7 64bit Macro to Add Text and Page Number to Top of Each Page Within Text Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,953
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Is there a reason you can't simply insert the required text, plus a PAGE field into the page header or footer?
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 12-06-2012, 08:30 PM
eslight eslight is offline Macro to Add Text and Page Number to Top of Each Page Within Text Windows 7 64bit Macro to Add Text and Page Number to Top of Each Page Within Text Office 2010 64bit
Novice
Macro to Add Text and Page Number to Top of Each Page Within Text
 
Join Date: Dec 2012
Posts: 7
eslight is on a distinguished road
Default

I certainly could do it manualy, but I have about 8,000 pages to do, with another 500 pages twice a year, and was hoping to automate the process.
Reply With Quote
  #4  
Old 12-06-2012, 08:33 PM
eslight eslight is offline Macro to Add Text and Page Number to Top of Each Page Within Text Windows 7 64bit Macro to Add Text and Page Number to Top of Each Page Within Text Office 2010 64bit
Novice
Macro to Add Text and Page Number to Top of Each Page Within Text
 
Join Date: Dec 2012
Posts: 7
eslight is on a distinguished road
Default

Quote:
Originally Posted by macropod View Post
Is there a reason you can't simply insert the required text, plus a PAGE field into the page header or footer?
Oh, and the final document can't have a header or footer.
Reply With Quote
  #5  
Old 12-06-2012, 08:37 PM
macropod's Avatar
macropod macropod is offline Macro to Add Text and Page Number to Top of Each Page Within Text Windows 7 64bit Macro to Add Text and Page Number to Top of Each Page Within Text Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,953
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Surprise yourself - access the page header and insert the text and a PAGE field (or create one by pressing Ctrl-F9 and typing PAGE between the field braces, then select the field and press F9. Then go back to the body of the document and have a look at what's in the header on a couple of pages. Go to the end of the document and add another page. Take a look at the page header.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #6  
Old 12-06-2012, 08:38 PM
eslight eslight is offline Macro to Add Text and Page Number to Top of Each Page Within Text Windows 7 64bit Macro to Add Text and Page Number to Top of Each Page Within Text Office 2010 64bit
Novice
Macro to Add Text and Page Number to Top of Each Page Within Text
 
Join Date: Dec 2012
Posts: 7
eslight is on a distinguished road
Default

Quote:
Originally Posted by eslight View Post
Oh, and the final document can't have a header or footer.
After the page notations are added, it's going to be converted into a text document, and the reader has to be able to see where the page numbers belong, so I need then to be in the body rather than the header.
Reply With Quote
  #7  
Old 12-06-2012, 08:38 PM
macropod's Avatar
macropod macropod is offline Macro to Add Text and Page Number to Top of Each Page Within Text Windows 7 64bit Macro to Add Text and Page Number to Top of Each Page Within Text Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,953
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Quote:
Originally Posted by eslight View Post
Oh, and the final document can't have a header or footer.
For what purpose cannot a document have a header or footer?
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #8  
Old 12-06-2012, 08:44 PM
eslight eslight is offline Macro to Add Text and Page Number to Top of Each Page Within Text Windows 7 64bit Macro to Add Text and Page Number to Top of Each Page Within Text Office 2010 64bit
Novice
Macro to Add Text and Page Number to Top of Each Page Within Text
 
Join Date: Dec 2012
Posts: 7
eslight is on a distinguished road
Default

Quote:
Originally Posted by macropod View Post
Surprise yourself - access the page header and insert the text and a PAGE field (or create one by pressing Ctrl-F9 and typing PAGE between the field braces, then select the field and press F9. Then go back to the body of the document and have a look at what's in the header on a couple of pages. Go to the end of the document and add another page. Take a look at the page header.
Actually, the docs I'm working with already have headers with page numbers. I receive them that way, already highly formatted. I need the page numbers to be in thethe body.I need to convert it to a txt document for archival purposes and need the reader to be able to determine where the original page numbers were. I have 8,000 pages to do and want to automate this process.
Reply With Quote
  #9  
Old 12-06-2012, 08:48 PM
eslight eslight is offline Macro to Add Text and Page Number to Top of Each Page Within Text Windows 7 64bit Macro to Add Text and Page Number to Top of Each Page Within Text Office 2010 64bit
Novice
Macro to Add Text and Page Number to Top of Each Page Within Text
 
Join Date: Dec 2012
Posts: 7
eslight is on a distinguished road
Default

Quote:
Originally Posted by macropod View Post
For what purpose cannot a document have a header or footer?
. I need to convert 8,000 pages of word docs into txt files for archival purposes. I need the reader of the txt file to be able to determine where the original page numbers belong.
Reply With Quote
  #10  
Old 12-07-2012, 08:13 PM
macropod's Avatar
macropod macropod is offline Macro to Add Text and Page Number to Top of Each Page Within Text Windows 7 64bit Macro to Add Text and Page Number to Top of Each Page Within Text Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,953
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Try the following macro:
Code:
Sub ApplyPageNos()
Application.ScreenUpdating = False
Dim Rng As Range, i As Long, StrTxt As String
StrTxt = "Page: "
With ActiveDocument
  .Fields.Unlink
  For i = (.ComputeStatistics(wdStatisticPages) - 1) To 1 Step -1
    Set Rng = .GoTo(What:=wdGoToPage, Name:=i)
    Set Rng = Rng.GoTo(What:=wdGoToBookmark, Name:="\page")
    With Rng
      .End = .End - 1
      If .Characters.Last.Text <> Chr(13) Then
        .Characters.Last.InsertAfter vbCr
      End If
      .InsertAfter vbCr & StrTxt & i + 1
    End With
  Next
  .Range.InsertBefore vbCr & StrTxt & "1"
End With
Set Rng = Nothing
Application.ScreenUpdating = True
End Sub
Note that it's necessary to unlink fields in the document; otherwise fields that span page breaks will invalidate the code for those pages. Even so, this doesn't convert bibliographies & citations to plain text. Likewise, the code won't work with endnotes (and even footnotes spanning page breaks won't be handled properly). You may also get odd results if a table spans a page break.

In reality, probably the safest way to do what you're after would be to convert the documents, with page #s in the headers, to PDF, then extract the content from there.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #11  
Old 12-07-2012, 08:18 PM
eslight eslight is offline Macro to Add Text and Page Number to Top of Each Page Within Text Windows 7 64bit Macro to Add Text and Page Number to Top of Each Page Within Text Office 2010 64bit
Novice
Macro to Add Text and Page Number to Top of Each Page Within Text
 
Join Date: Dec 2012
Posts: 7
eslight is on a distinguished road
Default Thanks

Thanks, I appreciate it. I will play around with that and see what works best.
Reply With Quote
Reply

Tags
macro, page numbering

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
2 page document printing problem, text from page 1 in layout of page 2 when printed laurawether45 Word 1 08-02-2012 07:03 AM
Macro to Add Text and Page Number to Top of Each Page Within Text Page number Macro kimsi Word 3 11-15-2011 11:54 PM
Macro to Add Text and Page Number to Top of Each Page Within Text How to Restore Page Margin Page Number Styles in Word 2010 cheech1981 Word 5 11-15-2011 04:16 AM
Add text to page numbers alpruett Word 0 07-07-2010 09:40 AM
One Page With Dynamic PAge Number 0x7C4 Word 0 08-17-2009 11:03 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 12:41 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft