kbrooks
07-27-2015, 09:42 AM
Hi,
I have the following code:
Sub ExtractChart(Location As String, BookmarkToUpdate As String, wb As WorkBook)
If ActiveDocument.Bookmarks.Exists(BookmarkToUpdate) = True Then
Dim BMRange As Range
Set BMRange = ActiveDocument.Bookmarks(BookmarkToUpdate).Range
BMRange.InlineShapes(1).Delete
wb.Sheets("Extraction_Charts").Range(Location).Copy
BMRange.PasteSpecial Link:=False, DataType:=wdPasteEnhancedMetafile, _
Placement:=wdInLine, DisplayAsIcon:=False
ActiveDocument.Bookmarks.Add BookmarkToUpdate, BMRange
End If
End Sub
Its function is to reference a bookmark which contains only an image and replace the image, with the bookmark remaining intact. The problem I'm having is that the bookmark, when being re-set, is empty and right after the image, and does not encapsulate the image.
I think the error probably lies in the InlineShapes function, or in the Bookmarks.Add part.
Anyone have any thoughts?
I have the following code:
Sub ExtractChart(Location As String, BookmarkToUpdate As String, wb As WorkBook)
If ActiveDocument.Bookmarks.Exists(BookmarkToUpdate) = True Then
Dim BMRange As Range
Set BMRange = ActiveDocument.Bookmarks(BookmarkToUpdate).Range
BMRange.InlineShapes(1).Delete
wb.Sheets("Extraction_Charts").Range(Location).Copy
BMRange.PasteSpecial Link:=False, DataType:=wdPasteEnhancedMetafile, _
Placement:=wdInLine, DisplayAsIcon:=False
ActiveDocument.Bookmarks.Add BookmarkToUpdate, BMRange
End If
End Sub
Its function is to reference a bookmark which contains only an image and replace the image, with the bookmark remaining intact. The problem I'm having is that the bookmark, when being re-set, is empty and right after the image, and does not encapsulate the image.
I think the error probably lies in the InlineShapes function, or in the Bookmarks.Add part.
Anyone have any thoughts?