We are trying to create a ppt report based on Excel data.
I'd like the first slide to have a background image or just an image that is set behind the text.
Sub generatePptWithCharts()
Dim coverImagePath As String
imagePath = "C:\Users\user\Documents\vitalias-ppt-cover.png"
'Powerpoint objects.
Dim PowPntApp As PowerPoint.Application
Dim PowPntPrsnt As PowerPoint.Presentation
Dim PowPntSlide As PowerPoint.Slide
'Excel objects.
Dim wbBook As Workbook
Dim wsSheet As Worksheet
Dim ChartObj As ChartObject
'Initialize the Excel objects.
Set wbBook = ThisWorkbook
Set PowPntApp = New PowerPoint.Application
PowPntApp.Visible = True
PowPntApp.Activate
Set PowPntPrsnt = PowPntApp.Presentations.Add
Set PowPntSlide = PowPntPrsnt.Slides.Add(1, ppLayoutTitle)
PowPntSlide.Shapes(1).TextFrame.TextRange = "Employee Information"
PowPntSlide.Shapes(2).TextFrame.TextRange = "by Presenter"
//This does not work properly
PowPntSlide.Shapes.AddPicture(imagePath, msoFalse, msoTrue, 0, 0, 960, 540).ZOrder msoSendToBack
PowPntPrsnt.SaveAs Environ("UserProfile") & "\Desktop\EmployeeInformation " & Format(Now, "yyyy-mm-dd hh-mm-ss") & ".pptx"
PowPntPrsnt.Close
PowPntApp.Quit
End Sub
The problem
The code generates the ppt with an image sent behind the text, but I am getting the following error message:
Methods 'close' of object '_Presentation' failed.
Also, the presentation does not close after saving it to the desktop.
I know it has to do with the way I am adding the image, because if I replace that line of code with the following code, it works properly (only the image is not behind the text):
PowPntSlide.Shapes.AddPicture Filename:=imagePath, _
LinkToFile:=msoFalse, _
SaveWithDocument:=msoTrue, _
Left:=0, _
Top:=0, _
Width:=960, _
Height:=540
What have I tried
Dim image As Shape
Set image = PowPntSlide.Shapes.AddPicture Filename:=imagePath, _
LinkToFile:=msoFalse, _
SaveWithDocument:=msoTrue, _
Left:=0, _
Top:=0, _
Width:=960, _
Height:=540
image.ZOrder msoSendBehindText
That code gives me a syntax error.