我正在尝试使用Excel VBA宏将形状从Powerpoint演示文稿复制到Excel模板。但是,我无法保留原始Powerpoint来源的格式。
这是我到目前为止获得的代码
Public Sub test()
Dim PPT As PowerPoint.Application
Dim p As PowerPoint.Presentation
Dim s As Slide
Dim aux_vec as Variant
Dim wkbk as Workbook
Set PPT = CreateObject("PowerPoint.Application")
PPT.Presentations.Open Filename:=src, ReadOnly:=True
Workbooks.Open "template.xlsx", ReadOnly:=True
Set wkbk = ActiveWorkbook
PPT.Activate
Set s = PPT.ActivePresentation.Slides(1) 'Slide to be copied
ReDim aux_vec(s.Shapes.Count)
For i = 1 To s.Shapes.Count
aux_vec(i) = i
Next i
s.Shapes.Range(aux_vec).Copy
Set wks = wkbk.Sheets("Sheet1") 'Destination sheet
wks.Select
wks.Range("C3").Select
wks.PasteSpecial 5 ' <--- Changes theme
End Sub
有什么想法吗?
编辑:修正了Ryan B评论后的代码段。
答案 0 :(得分:0)
我找到了一种解决方法: 我导出了Powerpoint演示文稿中使用的主题,并将其导入到Excel中。这样,形状将保持其格式。不是最佳选择,但对我有用。