#1
|
|||
|
|||
Macro to get first letter of a page in the header
Hi, we work on some book, and in the headertekst should be the first word of that page.
For example, if the first word on page 2 is 'When', there should be a W in the heading. I got the feeling i need to do something with docvariable, and macro's, but i just can't get it right. I can update all variables with 'just a text', but not with the first letter on a page. extra info: its a lot of pages, so doing it manually is not fun, thats why we try to do something like this.. |
#2
|
||||
|
||||
Hi faramir,
If this is for an ordinary document containing multi-line paragraphs, what you're asking for really isn't practicable. That's because any change in something as simple as printer - and even the configuration of the current printer driver - can change the pagination. Consequently, any 'marked' first words could end up on the previous page, or as the second word (or even the first word on the second line) of the current page. And, if even the smallest edit is made, the 'marked' first words could end up anywhere on the page - or even deleted. The only scenario in which this is practicable is if you're working with lists whose items are never more than one line long. Then, you could mark all first words with a particular character Style and use a STYLEREF field in the header to refer to that Style.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
Hi Paul, thanks for your response.
We are working with a large list, all rows max 1 line long. The list is sorted on name, and when the list reaches a new letter (from d to e), a new page starts. Can you give an example of the STYLEREF where you talk about? I don't have any experience with that. Thanks! Greetings, Erik |
#4
|
||||
|
||||
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 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 |
#5
|
|||
|
|||
Hi Paul,
Thanks for this, it works great! |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
How to save the current page in a new file with all the page settings (header, footer | Jamal NUMAN | Word | 6 | 03-15-2012 03:27 PM |
Header after page break | mashtonsmith | Word | 1 | 03-11-2011 10:21 AM |
Emailing Word letter with header & footer | PaulY | Word | 3 | 12-02-2010 12:13 PM |
How to print header logo only in 1st page | Shafraz Khahir | Word | 1 | 11-29-2010 11:52 AM |
Header disappear on 1st page; fix please? | deonholt | Word | 2 | 10-25-2010 12:47 AM |