1

I have Excel 2010 VBA macro which opens embedded word document from "sheet2" and fill "sheet1" selected row cell 1 text into "data1" bookmark inside word document.

Code works perfect until I close Word document manually. If I try to run code again after close, I get empty error message in VBA editor. How to fix this?

Sub update_bookmark()

    Dim oRng As Word.Range

    Set objWordTemplate = Sheets("sheet2").OLEObjects("Object 1")
    objWordTemplate.Activate
    objWordTemplate.Object.Application.Visible = True
    Worksheets("sheet1").Activate
    Set oRng = ActiveDocument.Bookmarks("data1").Range
    oRng.Text = Cells(Application.ActiveCell.Row, 1)
    ActiveDocument.Bookmarks.Add "data1", oRng
lbl_Exit:

End Sub
3

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.