簡體   English   中英

VSTO Word 2010加載項VB.net

[英]VSTO Word 2010 Add-in VB.net

目前,我已經編程了一個插件,該插件可從下拉菜單中為文檔的標題設置一個值。 它可以在頁眉或頁腳中使用,但是當前我的代碼都覆蓋了該部分中的所有內容。 當發送文檔或用戶嘗試使用模板時,這會導致問題。 知道如何將代碼與上面或下面的當前內容“合並”嗎?

代碼段:

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 +分類

但是請注意,它會破壞目前存在的格式...

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM