Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vba excel word粘贴命令失败_Vba_Excel - Fatal编程技术网

Vba excel word粘贴命令失败

Vba excel word粘贴命令失败,vba,excel,Vba,Excel,我正在运行一个excel程序,根据数据生成图表。然后我想将它导出到word并保存为pdf格式。 我在将图表粘贴到word中时遇到问题,因为我经常在word Paste专用行上出现错误“运行时错误”4198“命令失败”。我已将下面“导出”一词的代码包括在内 Option Explicit Sub word_export(numscans As Integer, rootpath As String, poleid As String) Dim n As Integer Dim i As Int

我正在运行一个excel程序,根据数据生成图表。然后我想将它导出到word并保存为pdf格式。 我在将图表粘贴到word中时遇到问题,因为我经常在word Paste专用行上出现错误“运行时错误”4198“命令失败”。我已将下面“导出”一词的代码包括在内

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

任何帮助都将不胜感激。

对此并不完全确定,但请尝试一下:

WDApp.Selection.Range.Select
WDApp.Selection.PasteSpecial Link:=False, DataType:=wdPasteMetafilePicture, _
        Placement:=wdInLine, DisplayAsIcon:=False

不幸的是,同样的问题occurs@user3414481字体那么恐怕我不知道。没有任何Excel可供测试。。。