如何通过单词自动化在同一页上插入两个页眉?-VB.NET



我正试图通过使用vb.net的word自动化将一个包含徽标和文本字段的页眉插入到我的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 DatabaseGUIAlliance_logo.png")
        .ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphLeft
        .ParagraphFormat.SpaceAfter = 24
    End With

关于如何将徽标和文本放在第一页的同一个页眉上,有什么建议吗?

您的第一个With-语句定义从第2页开始的页面的标题(因为wdHeaderFooterPrimary(,第二个With-语句定义第一页的标题(由于wdHeaderFooterFirstPage(。

如果将第一个With-语句的内容移动到第二个,则所有内容都应显示在第一页上。

微软引用的WdHeaderFooterIndex枚举表示:

wdHeaderFooterPrimary返回除文档或节的第一页之外的所有页面上的页眉或页脚。

我不知道它会如何显示。这篇文章可能会给你一些关于如何在Word文档中的特定位置插入图像的有用提示。


此外,调用oDoc.Sections(1).PageSetup.DifferentFirstPageHeaderFooter = True两次也没有意义。

如果要在左侧、中间或右侧插入多个页眉或页脚,请使用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

最新更新