我需要有关从Word文档复制到Publisher文档的帮助。我有一个包含许多表格的Word文档,每个表格都包含,
- 带有纯文本的单元格
- 带有格式化文本的单元格
- 带有图像的单元格
以下Word宏成功地将此类单元格复制到Office剪贴板:
Sub TestCopyToClipboard()
Dim doc As Document
Dim tbl As Table
Dim rng As Range
Set doc = ActiveDocument
Set tbl = doc.Tables(5)
' Copyright cell, plain text
Set rng = tbl.Cell(5, 2).Range
rng.MoveEnd wdCharacter, -1 ' Back up over cell separator
rng.Copy
DoEvents
' Caption cell, formatted text
Set rng = tbl.Cell(4, 2).Range
rng.MoveEnd wdCharacter, -1 ' Back up over cell separator
Set rng = rng.FormattedText
rng.Copy
DoEvents
' Image cell
Set rng = tbl.Cell(1, 2).Range
rng.InlineShapes(1).Select
Selection.CopyAsPicture
' ' The following does not work:
' Set rng = rng.InlineShapes(1).Range
' rng.CopyAsPicture
End Sub
使用Publisher VBA 我可以使用代码片段重现此复制
Set docWord = GetObject(wdFileName) ' Open Word file
Set tblWord = docWord.Tables(TableNo)
Set rngWord = tblWord.Cell(4, 2).Range ' Caption cell
rngWord.MoveEnd wdCharacter, -1 ' Back up over cell separator
rngWord.Copy
纯文本(格式化文本类似)。对于我尝试过的图像
' Copy image
Set rngWord = tblWord.Cell(1, 2).Range ' Image cell
rngWord.InlineShapes(1).Select
但我的智慧到此结束,因为字行
Selection.CopyAsPicture
不被接受,因为Publisher中的 Selection 对象不是Word中的对象。
我试图使用
Set shp = rngWord.InlineShapes(1)
shp.Copy
但赋值导致类型不匹配错误。
添加行
Debug.Print Selection.ShapeRange.Count
返回值 0。
那么,如何使用Publisher VBA 将Word文档中的图像复制到Office剪贴板?
为了清除剪贴板,我使用Clearing the clipboard in Office 365 中描述的子程序。这是我在这里或其他地方找到的唯一一个,它实际上清除了它,它适用于Word、Excel和Publisher。