我有Excel 2010 VBA宏从“sheet2”打开嵌入的word文档,并将“sheet1”选中的行单元格1文本填入word文档中的“data1”书签。
代码工作正常,直到我手动关闭Word文档。如果我尝试在关闭后再次运行代码,我会在VBA编辑器中收到空错误消息。如何解决这个问题?
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