1
votes

I'm trying to PasteSpecial an enhanced metafile into a Word bookmark, in-line with the text (as opposed to floating, which seems to be the default). Specifically, my Word macro opens an Excel doc, copies a range of cells, and pastes into Word. I know there's a wdInline parameter, but I learned that that only works with an OLE object, unfortunately.

The only thing I've come across online is the idea of using "Shapes" - specifically, to use the InlineShape object - but I haven't found a way to alter my code to make that work.

Dim objExcel As New Excel.Application
Dim wb As Excel.Workbook
Dim uniqueIdentifier As String
Dim numRows As Long
Dim excelPath As String

Prompt1:
excelPath = InputBox("Enter directory/path to Excel Interface Catalogue")

If excelPath <> "" Then
Prompt2:
    uniqueIdentifier = InputBox("Enter the interface's Unique Identifier")
    uniqueIdentifier = UCase(uniqueIdentifier)

    If uniqueIdentifier <> "" Then
    Set wb = objExcel.Workbooks.Open(excelPath)

    wb.Sheets("API Data Fields").Range("G8").Value = uniqueIdentifier *[**Excel function populates the cells referenced in next line**]*
    numRows = (wb.Sheets("API Data Fields").Range("J8").Value) + 10
    wb.Sheets("API Data Fields").Range(wb.Sheets("API Data Fields").Cells(10, 7), wb.Sheets("API Data Fields").Cells(numRows, 10)).EntireRow.AutoFit
    wb.Sheets("API Data Fields").Range(wb.Sheets("API Data Fields").Cells(10, 7), wb.Sheets("API Data Fields").Cells(numRows, 10)).Copy
    ActiveDocument.Bookmarks("FieldDefinition").Range.PasteSpecial DataType:=wdPasteEnhancedMetafile
1
So what is working or not working? What exactly is the end result you're trying to achieve?PeterT
@PeterT Everything is working, in terms of general copying and pasting, but it pastes the image "floating" over the text. I can go into the Word doc after the fact and right click and change the placement to "In line with text," and everything is perfect. I'd just prefer to have it paste with this formatting, via the macro.PGord

1 Answers

0
votes

As long as the Word version is not too old (not Word 2003) the PasteSpecial method has the argument Placement. This takes a WdOLEPlacement enum that determines how the object/graphical content is inserted: wdFloatOverText or wdInLine.

So...

ActiveDocument.Bookmarks("FieldDefinition").Range.PasteSpecial _
   DataType:=wdPasteEnhancedMetafile, Placement:=wdInLine