View Single Post
 
Old 11-16-2011, 03:19 AM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,467
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

Hi faramir,

This is something quite like a solution I provided for another organisation - see: http://www.tek-tips.com/viewthread.cfm?qid=1579057

If you run the following macro, it will add a 'RefWord' character style to your document and apply that style to the first word in every paragraph.
Code:
Sub StyleRefSetup()
Dim i As Integer
Application.ScreenUpdating = False
With ActiveDocument
  On Error Resume Next
  .Styles.Add Name:="RefWord", Type:=wdStyleTypeCharacter
  For i = 1 To .Paragraphs.Count
    .Paragraphs(i).Range.Words.First.Style = "RefWord"
  Next
End With
Application.ScreenUpdating = True
End Sub
You can then access the document's header to create the STYLEREF field. the simplest way to do this is to press Ctrl-F9 to create a pair of field braces (which look like '{}'), then type 'STYLEREF RefWord' between the braces so that you end up with '{STYLEREF RefWord}'. Press F9 and every page in the document will now have the first word on that page in its heading. Since every paragraph gets this treatment, changes to page sizes, margins & printers won't compromise the outcome.

PS: Your problem description is ambiguous - it's not clear whether you want the first word or the first character on each page in the heading. If it's only the first character, change:
.Paragraphs(i).Range.Words.First.Style = "RefWord"
to:
.Paragraphs(i).Range.Characters.First.Style = "RefWord"
In that case, I'd also suggest changing every reference to "RefWord" to "RefChar", so that the Style name & STYLEREF fields etc use a name consistent with their intention.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]

Last edited by macropod; 11-16-2011 at 03:27 AM. Reason: PS Added
Reply With Quote