[英]VBA Word Add selected inline shape to a table cell
我在 Word 中选择了一个内联形状对象,并尝试使用 VBA 将其粘贴(移动)到表格单元格中。 但我找不到任何 API 来完成这项工作。 我想这样做
// C#
myCell.InlineShapes.Add(selection.InlineShapes[1]);
但是我找不到 VBA 或 C# 中的 API 可以做到这一点。
我发现这个 SO 链接几乎可以完成工作,但它直接将图片从文件加载到表格单元格中。
如何将所选图像放入单元格(在 Shapes 或 InlineShapes 中)? 谢谢
更新:
我在这里找到了 Cindy Meister 的另一个例子,为我提供了正确方法的提示。 谢谢你,辛迪!!
这段代码终于奏效了。 我必须通过剪贴板并获取单元格范围才能使用 PasteSpecial 从剪贴板中提取图片。 奇怪的。 但它奏效了。 也许有更好的方法。
// C#
sel.CopyAsPicture();
var cell = table.Cell(row, 1);
// Must use cell.PasteSpecial to pull in the image from the clipboard
var range = cell.Range;
range.PasteSpecial(null, null, WdOLEPlacement.wdInLine, false,
WdPasteDataType.wdPasteShape);
试试这个代码:
Sub MoveShapeToTable()
Dim ish As InlineShape, tblNew As Table
On Error Resume Next
Set ish = Selection.InlineShapes(1)
If Err.Number <> 0 Then
MsgBox "No InlineShapes selected", vbCritical
Exit Sub
End If
On Error GoTo 0
ish.Range.Cut
With ActiveDocument
Set tblNew = .Tables.Add(Range:=.Range.Characters.Last, NumRows:=2, NumColumns:=1, _
DefaultTableBehavior:=wdWord9TableBehavior)
tblNew.Cell(1, 1).Range.Paste
End With
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.