Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 11-15-2011, 06:26 AM
faramir faramir is offline Macro to get first letter of a page in the header Windows 7 64bit Macro to get first letter of a page in the header Office 2010 64bit
Novice
Macro to get first letter of a page in the header
 
Join Date: Nov 2011
Posts: 3
faramir is on a distinguished road
Question 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..
Reply With Quote
  #2  
Old 11-15-2011, 11:45 PM
macropod's Avatar
macropod macropod is offline Macro to get first letter of a page in the header Windows 7 64bit Macro to get first letter of a page in the header Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
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,

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]
Reply With Quote
  #3  
Old 11-16-2011, 02:25 AM
faramir faramir is offline Macro to get first letter of a page in the header Windows 7 64bit Macro to get first letter of a page in the header Office 2010 64bit
Novice
Macro to get first letter of a page in the header
 
Join Date: Nov 2011
Posts: 3
faramir is on a distinguished road
Default

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
Reply With Quote
  #4  
Old 11-16-2011, 03:19 AM
macropod's Avatar
macropod macropod is offline Macro to get first letter of a page in the header Windows 7 64bit Macro to get first letter of a page in the header Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
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
  #5  
Old 11-16-2011, 05:43 AM
faramir faramir is offline Macro to get first letter of a page in the header Windows 7 64bit Macro to get first letter of a page in the header Office 2010 64bit
Novice
Macro to get first letter of a page in the header
 
Join Date: Nov 2011
Posts: 3
faramir is on a distinguished road
Default

Hi Paul,

Thanks for this, it works great!
Reply With Quote
Reply



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
Macro to get first letter of a page in the header 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
Macro to get first letter of a page in the header How to print header logo only in 1st page Shafraz Khahir Word 1 11-29-2010 11:52 AM
Macro to get first letter of a page in the header Header disappear on 1st page; fix please? deonholt Word 2 10-25-2010 12:47 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 09:54 PM.


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