Link to home
Start Free TrialLog in
Avatar of Lawlords
LawlordsFlag for Hong Kong

asked on

Setting Header of the Word Document with vba code

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

ASKER CERTIFIED SOLUTION
Avatar of Chris Bottomley
Chris Bottomley
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Lawlords

ASKER

Thanks very much Chris, you gave me a great help.
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