Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

word automation: adding more elements to the header

Status
Not open for further replies.

davikokar

Technical User
May 13, 2004
523
IT
Hallo,

I am using this code to insert an autotext into the header of a document.
The problem is that I would like to add a second element, but with this code the second would overwrite the first one:

Code:
Dim rng As Range
Set rng = ActiveDocument.Sections(1).Headers(1).Range
    
ActiveDocument.AttachedTemplate.AutoTextEntries("HeaderAddress").Insert Where:=rng, RichText:=True

ActiveDocument.AttachedTemplate.AutoTextEntries("HeaderTitle").Insert Where:=rng, RichText:=True

This is quite obvious, since I am using the same range to insert the two elements. But how can I say "insert it after this other element"... Another option would be to define a new range, something like "this range is after that range"...

Does someone has an hint? thanks
 
You could try it the other way round:
Code:
ActiveDocument.Sections(1).Headers(1).Range[b].InsertAfter[/b] ActiveDocument.AttachedTemplate.AutoTextEntries("HeaderAddress")

Cheers,
MiS

[navy]"We had to turn off that service to comply with the CDA Bill."[/navy]
- The Bastard Operator From Hell
 
Collapse the Range after the first Insert:

Code:
[blue]Dim rng As Range
Set rng = ActiveDocument.Sections(1).Headers(1).Range
    
ActiveDocument.AttachedTemplate.AutoTextEntries("HeaderAddress").Insert Where:=rng, RichText:=True

[red]rng.Collapse wdCollapseEnd[/red]

ActiveDocument.AttachedTemplate.AutoTextEntries("HeaderTitle").Insert Where:=rng, RichText:=True[/blue]

Enjoy,
Tony

------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.

I'm working (slowly) on my own website
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top