GRCNC
03-29-2017, 03:09 PM
Hi - Hopefully an easy question to answer... My Word document contains several Bookmarks as well as a UF. One of the purposes of the UF is to allow the end user to replace Bookmarks. I've got a combobox, user selects the Bookmark to be replaced and my macro opens up the appropriate file, and using the VBA command "Selection.InsertFile", copies the contents of the file and should replace the Bookmark in the active file with these contents from the newly opened file. The macro works as expected on all of the Bookmarks except 1. This 1 Bookmark contains a Table and when the macro tries to replace it, I'm getting the following error:
Runtime error '5260'
You cannot insert this selection into a table.
The file that I'm inserting has a table at the start of the document. I ended up putting a blank row before the table thinking that might help, but it didn't.
Anybody else come across this issue and find a solution?
Here is the code I'm using
Dim strPath As String
strPath = "C:\Users\jsmith\Documents\Word\Files" 'declare the path as a string variable
If ActiveDocument.Bookmarks.Exists("BK_Tires") = True Then
ActiveDocument.Bookmarks("BK_Tires").Select
Selection.InsertFile FileName:=strPath & "Accounting%20Folder%202017/File%20Summary%20Intro__1.docx"
Else
MsgBox "Can't replace Intro section. Bookmark does not exist."
End If
Runtime error '5260'
You cannot insert this selection into a table.
The file that I'm inserting has a table at the start of the document. I ended up putting a blank row before the table thinking that might help, but it didn't.
Anybody else come across this issue and find a solution?
Here is the code I'm using
Dim strPath As String
strPath = "C:\Users\jsmith\Documents\Word\Files" 'declare the path as a string variable
If ActiveDocument.Bookmarks.Exists("BK_Tires") = True Then
ActiveDocument.Bookmarks("BK_Tires").Select
Selection.InsertFile FileName:=strPath & "Accounting%20Folder%202017/File%20Summary%20Intro__1.docx"
Else
MsgBox "Can't replace Intro section. Bookmark does not exist."
End If