Results 1 to 2 of 2

Thread: Trouble Rewriting Bookmarks in Word Using VB.NET

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 2011
    Posts
    70

    Trouble Rewriting Bookmarks in Word Using VB.NET

    Right now I have a Word Document with the following text:

    FullName
    Position
    Address


    Each line is made as a separate bookmark. The bookmark name for each line is the same as the word (the bookmark for FullName is FullName).

    When I iterate through the bookmarks and update the text of the three different bookmarks, the first two get deleted and I am just left with the address. I think some how the bookmarks are getting combined in the editing process somehow.

    Here is the code I have:

    Dim saveFileDialog1 As New SaveFileDialog()
    saveFileDialog1.Filter = "Word|*.docx"
    saveFileDialog1.Title = "Save your report file"

    Dim FilePath = "C:\Users\Administrator.Laptop1\Desktop\TESTER.docx"
    Dim myWordDoc As Microsoft.Office.Interop.Word.Document
    Dim myWordApp As Microsoft.Office.Interop.Word.Application
    Dim filepathname As Object = TryCast(FilePath, Object)
    Dim missing As Object = Type.Missing
    Dim objTrue As Object = TryCast(True, Object)

    ' create Word.Application object for the document
    myWordApp = New Microsoft.Office.Interop.Word.Application

    ' open the document
    myWordDoc = myWordApp.Documents.Open(filepathname, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing)

    'update Opinion
    myWordDoc.Bookmarks("SendDate").Range.Text = (Convert.ToDateTime(TextBox7.Text)).ToString("MMMM dd, yyyy")
    myWordDoc.Bookmarks("FullName").Range.Text = TextBox4.Text & " " & TextBox5.Text & " " & TextBox6.Text & vbLf
    myWordDoc.Bookmarks("Position").Range.Text = TextBox8.Text & vbLf

  2. #2
    Frenzied Member
    Join Date
    May 2014
    Location
    Central Europe
    Posts
    1,388

    Re: Trouble Rewriting Bookmarks in Word Using VB.NET

    looks like you have to use a range to assign the text:
    http://word.mvps.org/faqs/macrosvba/...AtBookmark.htm

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width