A family of Microsoft word processing software products for creating web, email, and print documents.
As I indicated, the code I posted adds the line to ALL the header ranges in the document.
If you want to add it to just the first page header then
Dim shp As Shape
Dim oRng As Range
Dim oHeader As HeaderFooter
Dim oSection As Section
Set oSection = ActiveDocument.Sections(1)
oSection.PageSetup.DifferentFirstPageHeaderFooter = True
Set oHeader = oSection.Headers(wdHeaderFooterFirstPage)
Set oRng = oHeader.Range
Set shp = ActiveDocument.Shapes.AddLine(10, 100, 590, 100, oRng)
With shp.Line
.DashStyle = msoLineSolid
.ForeColor.RGB = RGB(0, 0, 139)
.Weight = 2.5
End With
You can do it in fewer lines
Dim shp As Shape
ActiveDocument.Sections(1).PageSetup.DifferentFirstPageHeaderFooter = True
Set shp = ActiveDocument.Sections(1).Headers(wdHeaderFooterFirstPage).Shapes.AddLine(10, 100, 590, 100)
With shp.Line
.DashStyle = msoLineSolid
.ForeColor.RGB = RGB(0, 0, 139)
.Weight = 2.5
End With
When working with ranges, there is no need to select the range in order to process it, but you must set the layout option to use a different first page.