Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #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: 22,375
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
 

Tags
macro, page numbering



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 02:11 AM.


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