vb.net微软word书签

时间:2016-05-12 16:35:59

标签: vb.net ms-word office-interop

有什么方法可以在word文档上创建书签吗?

我正在使用Microsoft.Office.Interop.Word.dll我知道如何更新word文档中现有书签的文字。

我想知道有没有办法创建书签。它不需要放在文档上只是为了看它enter image description here

通过这种方式,我可以更改书签文字

  Private Sub document()

        Dim objWdDoc As Object
        Dim objWord As Object
        objWord = CreateObject("Word.Application")
        objWdDoc = CreateObject("Word.Document")
        objWdDoc = objWord.Documents.Add("C:\Users\iml4203\Desktop\_korisno\Zahtjevikupca.docx")
        objWord.Visible = True

        With objWdDoc.Bookmarks
            .item("Bookmark1").Range.Text = "Test Bookmark"
            .item("Bookmark2").Range.Text = "Test Bookmark"
            .item("Bookmark2").Range.Text = "Test Bookmark"
        End With
    End Sub

1 个答案:

答案 0 :(得分:1)

只需使用Bookmark.Add即可创建新书签。这应该让你开始(未经测试!)......

 With objwDoc.Bookmarks.Add
     ' Set the individual properties of the bookmark here
 End With