Log in

View Full Version : Load and Manipulate Template



iago
11-26-2017, 07:51 PM
Hello! I'm generating some automatic PowerPoint presentations by copying and pasting data from several Excel workbooks. I have managed to do that successfully, but now I'm trying to load a template and then paste the Excel data on the template. After the data has been pasted, I will automatically save it as a non-template PowerPoint file.

Below is the code that I am successfully using to generate a PowerPoint presentation and then paste the data I've copied from Excel. Thanks.

21063


I didn't manage to past it here with the highlighting included (although I did copy it including the highlighting from Notepad++), so I'm attaching a word file also in case anybody is interested in copying the script.

John Wilson
11-27-2017, 02:46 AM
This is how to start a new presentation based on a potx template


Presentations.Open "<Path to potx>", Untitled:=True

iago
11-27-2017, 03:32 AM
I forgot to mention a very important detail. I'm trying to open a file in the same folder where the macro is saved. When I'm opening a workbook, I use this code and it works fine:


Workbooks.Open (ThisWorkbook.Path & ".\workbook1.xlsx")


The macro in this case is still stored in a macro-enabled workbook file, so I thought of also using the ThisWorkbook.Path command. I tried the code below and it doesn't work.


Presentations.Open (ThisWorkbook.Path & ".\template1.potx"), Untitled:=True

Furthermore, I also need to associate the newly opened template document with a VBA variable so that I can manipulate it the same way I was doing with a presentation created from scratch.

Many thanks.

John Wilson
11-27-2017, 06:52 AM
This works for me from excel


Sub openTemplate()
Dim ppt As Object
Dim ppttemp As Object
Set ppt = CreateObject(Class:="PowerPoint.Application")
Set ppttemp = ppt.presentations.Open(ThisWorkbook.Path & "\notBlank.potx", untitled:=True)
End Sub

iago
11-30-2017, 04:40 AM
Thank you John.

Now if you were to save this same presentation as a .pptx file on the same folder of the macro, how would you do it?