Solved

Setting Header of the Word Document with vba code

Posted on 2011-02-15
3
354 Views
Last Modified: 2012-05-11
Dear all,

I wish to design a macro for setting the header of the document with the code below but the result ended up with all 3 lines on the left. Can any help to resolve the problem?

Line 1 on the Right
Line 2 on the Left
Line 3 on the Left

Thanks very much

   

With ActiveDocument.sections(1).Headers(wdHeaderFooterPrimary).Range
    
        .Text = "Line 1 on the Right" & Chr(10)
        .Paragraphs.Alignment = wdAlignParagraphRight
    
        .InsertAfter "Line 2 on the Left" & Chr(10)
        .Paragraphs.Alignment = wdAlignParagraphLeft
    
        .InsertAfter "Line 2 on the Left"
        .Paragraphs.Alignment = wdAlignParagraphLeft
    
    
    End With

Open in new window

0
Comment
Question by:Lawlords
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 59

Accepted Solution

by:
Chris Bottomley earned 500 total points
ID: 34897442
Try as below ... setting the cursor after the text inserted at the rignt.

Chris
With ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Range
    
    .Paragraphs.Alignment = wdAlignParagraphRight
    .Text = "Line 1 on the Right" & Chr(10)
    .Collapse wdCollapseEnd

    .Paragraphs.Alignment = wdAlignParagraphLeft
    .InsertAfter "Line 2 on the Left" & Chr(10)
    .InsertAfter "Line 2 on the Left"
    
    
End With

Open in new window

0
 

Author Closing Comment

by:Lawlords
ID: 34897468
Thanks very much Chris, you gave me a great help.
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 34897541
Word can be very finicky with the methods used for populating text so you are not alone, (I struggle too).

Thank you for the prompt closure and grade.

Chris
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Office Picture Manager is not included in Office 2013. This comes as a shock to users upgrading from earlier versions of Office, such as 2007 and 2010, where Picture Manager was included as a standard application. This article explains how…
This article describes how to use the Send to Mail Recipient command. The instructions apply generally to Office 2007 and later versions, but Microsoft® Word 2013 was used for the specific steps and figures.  What is Send to Mail Recipient? Send…
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
The viewer will learn how to  create a slide that will launch other presentations in Microsoft PowerPoint. In the finished slide, each item launches a new PowerPoint presentation and when each is finished it automatically comes back to this slide: …

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question