开发者

VB.NET Microsoft Office Interop Bookmarks

I am working on a project which will include automatically filling out some templates. I plan to use word bookmarks to create the templates and then fill them in via VB. This would be no problem, but the problem is that I would like to allow other templates to be used. Is there a way I can open a word document and get all the bookmarks out of it? I need a list, so I can determine which ones I am able to fill out, then send the correct values. Here is the code I am working with if you need a refresher.

    Imports Microsoft.Office.Interop


    Dim oWord As Word.Application
    Dim oDoc As Word.Document

    oWord = CreateObject("Word.Application")
    oWord.Visible = True
    oDoc = oWord.Documents.Add("Z:\DJ\Documents\Reminder_Letter.doc")
    oDoc.Bookmarks("full_name").Range.Text = "John Smith"

Basica开发者_开发百科lly, I just want to make sure that "full_name" exists in a document before I try to add a value to it, so I need a list of bookmarks in the document.

Thanks, Kevin


It will be faster to use the Exists function of the bookmark's collection :

 oDoc.Bookmarks.Exists("bookmark name")


Just iterate through the bookmarks collection, checking the name.

Something like

   For each bm in oDoc.bookmarks
       if bm.Name = "blah" then
           'this is my bookmark
       end if
   next
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜