VSTO Word 2010加载项VB.net

VSTO Word 2010加载项VB.net,vb.net,vsto,Vb.net,Vsto,目前,我已经编写了一个外接程序,用于设置从下拉菜单到文档标题的值。它可以放在页眉或页脚中,但“我的代码”当前会覆盖该部分中的所有内容。当发送文档或用户尝试使用模板时,这会导致问题。你知道我如何将代码与当前的代码“合并”到上面或下面吗 代码段: Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click On Error GoTo err Dim classification

目前,我已经编写了一个外接程序,用于设置从下拉菜单到文档标题的值。它可以放在页眉或页脚中,但“我的代码”当前会覆盖该部分中的所有内容。当发送文档或用户尝试使用模板时,这会导致问题。你知道我如何将代码与当前的代码“合并”到上面或下面吗

代码段:

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

    On Error GoTo err

    Dim classification As String
    Dim dc As Microsoft.Office.Interop.Word.Document

    dc = Globals.ThisAddIn.Application.ActiveDocument
    classification = "Classification: " & ComboBox1.Text

    With dc

        .ActiveWindow.View.SeekView = Word.WdSeekView.wdSeekCurrentPageHeader
        .ActiveWindow.Selection.HeaderFooter.Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter
        .ActiveWindow.Selection.HeaderFooter.Range.Text = classification
        .ActiveWindow.View.SeekView = Word.WdSeekView.wdSeekMainDocument

    End With

    Me.Hide()

    Exit Sub
只是为了让您知道,您可以看到的额外代码是搜索当前不存在的分类,如果存在,则不显示表单(如下所示)

谢谢


查尔斯

我已经为任何感兴趣的人想出了这个办法,你可以交换线路

ActiveWindow.Selection.HeaderFooter.Range.Text=分类

与下面的一个:

.ActiveWindow.Selection.HeaderFooter.Range.Text=.ActiveWindow.Selection.HeaderFooter.Range.Text+分类

但是,请注意,它破坏了当前存在的格式