I am trying to insert a header that includes a logo and a text field onto the FIRST PAGE of my word document through word automation using vb.net.
So far I have gotten the logo to show up on the right side, but I cannot seem to get the text to display on the left side of the header of the first page. Instead it will display on the second page.
Below is my code:
'Insert header notes.
oDoc.Sections(1).PageSetup.DifferentFirstPageHeaderFooter = True
With oDoc.Sections(1).Headers(Word.WdHeaderFooterIndex.wdHeaderFooterPrimary).Range
.Font.Bold = False
.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphRight
.Text = "The Shareholder Communication Strategists"
.Font.Size = 10
End With
oDoc.Sections(1).PageSetup.DifferentFirstPageHeaderFooter = True
With oDoc.Sections(1).Headers(Word.WdHeaderFooterIndex.wdHeaderFooterFirstPage).Range
.InlineShapes.AddPicture("S:\Databases\^Tyler & Rich Database\GUI\Alliance_logo.png")
.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphLeft
.ParagraphFormat.SpaceAfter = 24
End With
Any suggestions on how I can put a logo and a text on the same header of the first page?
Your first With
-statement defines the headers of the pages starting at page 2 (because of wdHeaderFooterPrimary
) and the second With
-statement defines the header of the first page (because of wdHeaderFooterFirstPage
).
If you move the content of the first With
-statement to the second one, everything should display on the first page.
Microsoft’s reference of WdHeaderFooterIndex Enumeration says:
wdHeaderFooterPrimary Returns the header or footer on all pages other than the first page of a document or section.
I don't know how it will display. This article might give you some usefull hints on how to Insert Images at Specific Locations in Word Document.
Also, there is no point in calling oDoc.Sections(1).PageSetup.DifferentFirstPageHeaderFooter = True
twice.