将图表从Excel复制到Word

我正在尝试将图表复制到Word中。 我查了一个方法 ,说要做这样的事情:

Dim wordApp As Object Dim wordDoc As Object Set wordApp = CreateObject("Word.Application") wordApp.Visible = True Set wordDoc = wordApp.Documents.Add With ThisWorkbook .Sheets("Sheet1").ChartObjects(1).Activate .ActiveChart.ChartArea.Copy End With With Selection .PasteSpecial Link:=False, DataType:=wdInLine, _ Placement:=wdInLine End With wordApp.Documents.Close wordApp.Application.Quit 

我试图改变With selection部分只是wordApp.Documents.Selection.Pastespecial导致一些奇怪的事情发生,并以某种方式粘贴在工作簿中的第一个工作表的屏幕截图,并崩溃的Excel。 任何build议感激。

你的代码的这一部分有问题:

 With Selection .PasteSpecial Link:=False, DataType:=wdInLine, _ Placement:=wdInLine End With 

你可以解决你的问题,改变它:

 With wordDoc.Application.Selection .PasteSpecial Link:=False, DataType:=wdInLine, _ Placement:=wdInLine End With 

说明:从Excelmacros中运行代码,Selection对象将parsing为Excel工作表中的当前select,您需要指定select的范围,以将您的命令应用于Word文档而不是当前的Excel工作簿。