我知道之前已经问过这个问题,但由于我不是VBA专家,我似乎无法让任何解决方案适用于我的特定场景,所以我希望有人可以提供帮助。
我有一些VBA代码可以复制Excel中的选项,根据模板打开一个新的powerpoint演示文稿,然后将数据粘贴到powerpoint的第二张幻灯片中。
我现在唯一想做的就是操作图表的大小和位置。我需要在下面的代码中添加什么来实现这一目标?
'Opens a new PowerPoint presentation based on template and pastes data into Slide 2 of Powerpoint from Excel
Dim PPapp As PowerPoint.Application, PPpres As PowerPoint.Presentation, PPslide As PowerPoint.Slide
Dim XLws As Worksheet
Set XLws = ActiveSheet
Set PPapp = New PowerPoint.Application
Set PPpres = PPapp.Presentations.Open("C:\Users\Colin\Dropbox (Edge45)\Edge45 Team Folder\Edge45 Company Documents\Templates\Powerpoint Templates\Edge45 Audit Template Macro.potm", Untitled:=msoTrue)
PPapp.Visible = True
Set PPslide = PPpres.Slides(2)
XLws.Range("A1:D16").Copy
PPslide.Shapes.PasteSpecial DataType:=ppPasteHTML, Link:=msoFalse
Application.CutCopyMode = False
答案 0 :(得分:2)
定义一个Shape对象并玩弄:
'Opens a new PowerPoint presentation based on template and pastes data into Slide 2 of Powerpoint from Excel
Dim PPapp As PowerPoint.Application, PPpres As PowerPoint.Presentation, PPslide As PowerPoint.Slide, PPShape As Object
Dim XLws As Worksheet
Set XLws = ActiveSheet
Set PPapp = New PowerPoint.Application
Set PPpres = PPapp.Presentations.Open("C:\Users\Colin\Dropbox (Edge45)\Edge45 Team Folder\Edge45 Company Documents\Templates\Powerpoint Templates\Edge45 Audit Template Macro.potm", Untitled:=msoTrue)
PPapp.Visible = True
Set PPslide = PPpres.Slides(2)
XLws.Range("A1:D16").Copy
Set PPShape = PPslide.Shapes.PasteSpecial(DataType:=ppPasteHTML, Link:=msoFalse)
Application.CutCopyMode = False
With PPShape
.Top = 10
.Height = 100
.Left = 10
.Width = 100
End With