将数据透视表从excel粘贴到Powerpoint

时间:2018-03-26 09:00:28

标签: excel excel-vba pivot-table powerpoint vba

我正在尝试创建一个自动创建powerpoint演示文稿的工具。基本上我有一个现有的powerpoint文件,我需要在指定的每张幻灯片上粘贴几个数据透视表。现在,我正在测试使用下面的代码粘贴幻灯片3中的数据透视表。但是我收到了一些错误:

Sub Presentation()

Dim PPApp  As PowerPoint.Application
Dim PPPres As PowerPoint.Presentation
Dim PPSlide As PowerPoint.Slide
Dim sPath As String
Dim sSaveTo As String
Dim sFileName As String
Dim sDate As String
Dim FinalName As String
'On Error Resume Next
Dim pvt As PivotTable

Set pvt = Sheet1.PivotTables("PivotTable1")

sPath = Range("RangePath").Value
sSaveTo = Range("RangeSaveTo").Value
sDate = Format(Now(), "DD-MMM-YYYY hh mm AMPM")

sFileName = Range("RangeFileName").Value
FinalName = sSaveTo & sFileName

    Set PPApp = New PowerPoint.Application
    'Reference active presentation
    Set PPPres = PPApp.Presentations.Open(sPath)

    pvt.TableRange1.Copy
    ' Paste chart  to Slide #3
    With PPPres.Slides(3).Shapes.PasteSpecial '<~~~~~This is where I get an error

        .Left = 45
        .Top = 34

    End With

Application.CutCopyMode = False

'MsgBox ("Presentation has been created!"), vbOKOnly

PPApp.ActivePresentation.SaveAs FinalName & " " & sDate
waiting (7)
PPApp.Quit   

End Sub

以下是我收到的错误:

enter image description here

有人知道如何处理在特定幻灯片上粘贴数据透视表的方法吗?

1 个答案:

答案 0 :(得分:0)

from tkinter import *


root = Tk()
root.geometry("300x300")

def sum():
    add = e1.get()+ e2.get()
    print(add)

def Only_Integer(S):
    if S in ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']:
        return True                                                       
     return False

vcmd = (root.register(Only_Integer), '%S')

e1 = Entry(root, validate='key', vcmd=vcmd)
e1.pack()

e2 = Entry(validate='key', vcmd=vcmd)
e2.pack()

b = Button(root, text="calculate", command=sum)
b.pack(side=BOTTOM)

root.mainloop()

这样的东西?在上面的示例中,您将 With PPPres.Slides(3).Shapes .PasteSpecial .Left = 45 .Top = 34 End With 放在同一行.PasteSpecial上。