Runtime Error 424 : Object Required - when pasting string variable from Excel to Word Bookmarks.

  • Hi people.

    I have a word document that contains four bookmarks unsurprisingly named "Bookmark_1", "Bookmark_2", "Bookmark_3" and "Bookmark_4".

    I want to paste a different sentence from Excel into each bookmark. The sentence to be pasted is chosen based on where it should appear in the document and the value of a variable named Status.

    The bookmark name should be retained and not destroyed when pasting the new text as the document is cycled through several times, with successive documents containing different text based on the value of status.

    The value of the Status variable is obtained from elsewhere with the original Excel sheet, but I replicated it manually in this Sub just to make the selection process work.

    My issue is copying the chosen text in the Text(n) string into the bookmarks in the Word Document - which I seem unable to achieve.

    Having watched several video's on you tube and read some articles stating how 'easy' it is, I managed to replicate their demonstration but have failed to successfully implement it into my worksheet.


    The original example used this which I understand is pulling the text from a worksheet cell A1 which works just fine in testing.


    With objWord.ActiveDocument

    .Bookmarks("Text2").Range.Text = ws.Range("A1").Value


    However because I'm pulling from a string and not a cell, I get an error message "Runtime Error 424: Object Required


    Can someone please advise where I'm going wrong?


    Many thanks


    Smudge







  • Strings don't have properties, so you just use Text_1 for example, and not Text_1.Value

    Rory
    Theory is when you know something, but it doesn’t work. Practice is when something works, but you don’t know why. Programmers combine theory and practice: nothing works and they don’t know why

  • Wow - something so simple.

    This now works as I would expect.

    Thanks very much for pointing me in the right direction. I've been staring at this for weeks... and now I also understand a little more as to where my error was.


    Smudge

  • Glad to help. (I guess you should have posted sooner ;) )

    Rory
    Theory is when you know something, but it doesn’t work. Practice is when something works, but you don’t know why. Programmers combine theory and practice: nothing works and they don’t know why