Inserting text into Word bookmarks problem

  • Can you spot where I have gone wrong as it doesn't come up with any errors but it doesn't work when I click the button (I have double checked the name of the bookmark):

    Private Sub btn1_Click()
    Dim MyText As String
    Dim MyRange As Range

    'Identify current Bookmark range and insert text
    Set MyRange = ActiveDocument.Bookmarks("Para1").Range

    MyText = "wee!"

    'Re-insert the bookmark
    ActiveDocument.Bookmarks.Add "Para1", MyRange

  • Re: Inserting text into Word bookmarks problem


    Hi,

    Solved the problem. If anybody has a similar problem this is my revised code:

    Public Sub btn1_Click()

    Dim MyRange As Word.Range


    ''Identify current Bookmark range and insert text

    Set MyRange = ActiveDocument.Bookmarks("Para1").Range

    MyRange.Text = "Wee!"


    ''Re-insert the bookmark
    ActiveDocument.Bookmarks.Add "Para1", MyRange



    End Sub

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!