我正在尝试通过使用vb.net的文字自动化将包含徽标和文本字段的标题插入到我的word文档的第一页上。
到目前为止,我已经将徽标显示在右侧,但我似乎无法将文本显示在第一页标题的左侧。相反,它将显示在第二页上。
以下是我的代码:
'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
有关如何在第一页的同一标题上添加徽标和文字的任何建议吗?
答案 0 :(得分:1)
您的第一个With
- 语句定义从第2页开始的页面标题(因为wdHeaderFooterPrimary
),第二个With
- 语句定义第一页的标题(因为wdHeaderFooterFirstPage
)。
如果您将第一个With
- 语句的内容移动到第二个,则所有内容都应显示在第一页上。
微软对WdHeaderFooterIndex Enumeration的引用说:
wdHeaderFooterPrimary 返回除文档或部分的第一页以外的所有页面上的页眉或页脚。
我不知道它会如何显示。本文可能会为您提供有关如何Insert Images at Specific Locations in Word Document。
的一些有用提示此外,调用oDoc.Sections(1).PageSetup.DifferentFirstPageHeaderFooter = True
两次没有意义。
答案 1 :(得分:1)
如果要在左侧,中央或右侧插入多个页眉或页脚,请使用wdAlignParagraphLeft
并在带有制表符的位置之间切换。
With oDoc.Sections(1).Headers(Word.WdHeaderFooterIndex.wdHeaderFooterPrimary).Range
.Font.Bold = False
.Font.Size = 10
.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphLeft
.Text = "Left" & vbTab & "Center" & vbTab & "Right"
End With