PDA

View Full Version : Solved: Update a Slide



kbsudhir
01-24-2011, 12:57 AM
Hi,

I have a ppt template here where I have to change name of the candiate only.

I have the list of candidates in an excel file. How can I automate it so at the button click of the excel file, the ppt template is updated with the candidate's name & the file is saved with the candidate's name.

Please guide.

Regards
Sudhir

kbsudhir
01-26-2011, 08:53 AM
Its done. I added a textbox at the desired location on the slide & provided the input.

Thanks
Sudhir

kbsudhir
01-28-2011, 03:40 AM
Hi All,

Below is the code to update a slide from excel. I have inserted a textbox to ensure the data is updated at the correct area on the slide.


Sub Update_Slide()
Set olPPt = CreateObject("powerpoint.Application")
strFile = "C:\Documents and Settings\sudhir_kb\My Documents\Temp test - Macro.potm" 'Change This as required

olPPt.Visible = True
olPPt.Presentations.Open (strFile)

Dim cnt As Integer
cnt = 2

Do Until Range("A" & cnt) = ""

olPPt.ActivePresentation.Slides(1).Select
olPPt.ActivePresentation.Slides(1).Shapes("TextBox 2").Select ' Object index is 6 in this slide (FYI)
CandidateName = Trim(Range("A" & cnt).Value)
CandidateName = Replace(CandidateName, ".", " ")
olPPt.ActivePresentation.Slides(1).Shapes(6).TextFrame.TextRange.Text = CandidateName
olPPt.ActivePresentation.SaveAs "C:\Documents and Settings\sudhir_kb\My Documents\Certificates\" & Range("B" & cnt).Value & "-" & Range("A" & cnt).Value, ppSaveAsPDF
Range("D" & cnt).Value = "Yes"


cnt = cnt + 1
Loop


End Sub


I am using Office 2007. Do not forget to check the microsoft powerpoint as reference.

Thanks
Sudhir

John Wilson
01-28-2011, 07:47 AM
Just for reference it's almost always unecessary to select in powerPoint code

The two lines below are completey redundant
olPPt.ActivePresentation.Slides(1).Select
olPPt.ActivePresentation.Slides(1).Shapes("TextBox 2").Select

kbsudhir
01-28-2011, 08:21 AM
Thanks John, this was my first cod which worked & also my first attempt to write a macro for powerpoint.

Hence this error. Thanks for pointing that out as it just skipped me. I will take off the first line of code.

Thanks
Sudhir