That should not be necessary. The following will do what you want.
.ActiveDocument.Bookmarks("cuenta").Range.InsertBefore Range(rg).Value
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Basically I have different versions of this excel file since I'm adding functionality and newer versions give the error while using the exact same word template.
Working version:
.Documents.Add "C:\path\template.dotx"
rg = "B" + CStr(i)
Range(rg).Copy
.Selection.Goto wdGoToBookmark, , , "cuenta"
.Selection.PasteSpecial xlPasteValues
Non-Working version:
Select Case tipo
Case "typeOne"
template = "template.dotx"
Case "typeTwo"
template = "templateTwo.dotx"
Case "typeThree"
template = "templateThree.dotx"
End Select
template = temPath + template
.Documents.Add template
rg = "B" + CStr(i)
Range(rg).Copy
.Selection.Goto wdGoToBookmark, , , "cuenta"
.Selection.PasteSpecial xlPasteValues
The template.dotx file is exactly the same in both cases, and I've checked and the path gets generated properly.
The document.add doesn't fail so I imagine the file has been properly added, still, the PasteSpecial fails with Runtime Error 5101 (bookmark not found).
How do I fix this?
Thanks.,
That should not be necessary. The following will do what you want.
.ActiveDocument.Bookmarks("cuenta").Range.InsertBefore Range(rg).Value
Thanks @Doug Robbins - MVP !
Almost, the InsertBefore would keep the text on the bookmark so I did:
.ActiveDocument.Bookmarks("cuenta").Range.PasteSpecial xlPasteValues
Which worked like a charm.
Thanks!!