繁体   English   中英

如何从Excel中将与文本内联的增强型图元文件“粘贴特殊”到Excel中?

[英]How to 'PasteSpecial' an enhanced metafile inline with text into Word from Excel?

我正在尝试将增强型图元文件粘贴到Word书签中,并与文本一致(而不是浮动,这似乎是默认设置)。 具体来说,我的Word宏打开一个Excel文档,复制一系列单元格,然后粘贴到Word中。 我知道有一个wdInline参数,但是不幸的是,我了解到它仅适用于OLE对象。

我在网上遇到的唯一一件事是使用“形状”的想法,特别是使用InlineShape对象的想法,但是我还没有找到改变我的代码来使其工作的方法。

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

只要Word版本不是太旧(不是Word 2003), PasteSpecial方法就具有参数Placement 这需要一个WdOLEPlacement枚举,该枚举确定如何插入对象/图形内容: wdFloatOverTextwdInLine

所以...

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM