[英]How to add a picture to a powerpoint slide from excel
我设置了一个宏,该宏将Excel电子表格中的某些图表另存为图片(作为较大过程的一部分),并且需要一些代码将这些图片(每张幻灯片一张)粘贴到幻灯片中。
目前,我已经成功地打开了PowerPoint演示文稿,其中包含4张空白幻灯片,甚至还没有成功导入1张图片。
我一直在使用诸如shape.addpicture(“ C:\\ Users \\ restofpathname”)之类的方法,但没有设法使它们起作用
这是使我能够从excel中放图片的代码。 下面的代码有效,并且此链接也很有用
Dim applPP As PowerPoint.Application, prsntPP As PowerPoint.Presentation, TitlePage As PowerPoint.Slide
Set applPP = New PowerPoint.Application
applPP.Visible = True
Set prsntPP = applPP.Presentations.Add
Set TitlePage = prsntPP.Slides.Add(Index:=1, Layout:=ppLayoutTitle)
prsntPP.SaveAs ("C:\Users\...")
Dim oSlide As PowerPoint.Slide
Dim oPicture As PowerPoint.Shape
Set oSlide = prsntPP.Slides(1)
Set oPicture = oSlide.Shapes.AddPicture("C:\Users\Public\Pictures\Sample Pictures\Penguins.jpg", _
msoFalse, msoTrue, 1, 2, 3, 4)
oPicture.ScaleHeight 0.9, msoTrue
oPicture.ScaleWidth 0.9, msoTrue
With prsntPP.PageSetup
oPicture.Left = (.SlideWidth \ 2) - (oPicture.Width \ 2)
oPicture.Top = (.SlideHeight \ 2) - (oPicture.Height \ 2)
End With
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.