我正在运行一个基于数据生成图表的Excel程序。然后我想将其导出为word并将其另存为pdf。 我遇到了将图表粘贴到单词中的问题,因为我经常在Word Paste Special行上遇到错误“运行时错误”4198“命令失败”。我在下面的单词export中包含了代码。
Option Explicit
Sub word_export(numscans As Integer, rootpath As String, poleid As String)
Dim n As Integer
Dim i As Integer
Dim WDApp As Word.Application
Dim WDDoc As Word.Document
Set WDApp = CreateObject("Word.Application")
Set WDDoc = WDApp.Documents.Add
Application.Wait (Now + TimeValue("0:00:01"))
WDApp.DisplayAlerts = wdAlertsNone
For n = 1 To numscans
For i = 1 To Sheets("Scan" & n).ChartObjects.Count
Sheets("Scan" & n).ChartObjects(i).Chart.CopyPicture _
Appearance:=xlScreen, Size:=xlScreen, Format:=xlPicture
WDApp.Selection.Range.PasteSpecial Link:=False, DataType:=wdPasteMetafilePicture, _
Placement:=wdInLine, DisplayAsIcon:=False
WDApp.Selection.MoveEnd wdStory
WDApp.Selection.Move
Next
Next
WDDoc.SaveAs rootpath & "\" & poleid & " Summary.pdf", wdFormatPDF
WDApp.Quit wdDoNotSaveChanges
Set WDDoc = Nothing
Set WDApp = Nothing
End Sub
任何帮助都将不胜感激。
答案 0 :(得分:0)
不完全确定这个,但是试一试:
WDApp.Selection.Range.Select
WDApp.Selection.PasteSpecial Link:=False, DataType:=wdPasteMetafilePicture, _
Placement:=wdInLine, DisplayAsIcon:=False