如何通过word automation在同一页上插入两个标题?-VB.NET

如何通过word automation在同一页上插入两个标题?-VB.NET,vb.net,word-automation,Vb.net,Word Automation,我正在尝试使用vb.net通过word automation将包含徽标和文本字段的标题插入到word文档的第一页 到目前为止,我已经让徽标显示在右侧,但我似乎无法让文本显示在第一页页眉的左侧。相反,它将显示在第二页上 下面是我的代码: 'Insert header notes. oDoc.Sections(1).PageSetup.DifferentFirstPageHeaderFooter = True With oDoc.Sections(1).Headers(Word.Wd

我正在尝试使用vb.net通过word automation将包含徽标和文本字段的标题插入到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

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

您的第一个
With
-语句定义了从第2页开始的页眉(因为
wdheaderfooterprisary
),第二个
With
-语句定义了第一页的页眉(因为
wdHeaderFooterFirstPage

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

微软的参考资料说:

WDHeaderFooEnterprise返回除文档或节的第一页以外的所有页面上的页眉或页脚

我不知道它将如何显示。这篇文章可能会给你一些有用的提示如何显示



此外,调用
oDoc.Sections(1).PageSetup.differentitfirstpageheaderfooter=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

你知道现在如何格式化吗?因为现在文本显示在左侧。相反,它与徽标一起显示在右侧。你可以尝试先插入徽标,然后插入文本。但也可以查看我插入的链接。