Kirill_Temchuk
New Member
- Joined
- Jan 3, 2017
- Messages
- 1
Hello,
I am super new to VBA, and already got stuck in completing one task. So if it is possible, please help me out with this one.
The idea is to merge all one-slider ppt presentations (all are in one folder) for corresponding person listed in the excel file. The challenge for me is that there is no strict ppt file name listed in excel worksheet only the name, id and e-mail for each person (e.g name listed in excel: "Iron Man", one-slider name for this person is: "Riga Marvel Iron Man.ppt").
So far I found a solution to merge ppt slide listed in excel if the value in the cell is 100% match to the ppt file name.
This is the example of excel table:
<tbody>
</tbody>
Those are ppt files name:
Riga Marvel Wonder Woman.ppt
Riga Marvel Iron Man.ppt
Riga Marvel Green Lantern.ppt
Riga Marvel Spider Man.ppt
Riga Marvel Luke Cage.ppt
This is my code on the moment:
Sub Procedure1()
Dim objPowerPoint As Object
Dim objTemplate As Object
Set objPowerPoint = CreateObject(Class:="PowerPoint.Application")
'setting up the path to powerpoit template
Const strTemplatePath As String = "C:\Users\kirills.temcuks\Desktop\for macros\TEMPLATE.ppt"
'setting "save as" path.
Const strSaveAs As String = "C:\Users\kirills.temcuks\Desktop\TEMPLATE.ppt"
'setting path with "one-sliders.
Const strWorkFolder As String = "C:\Users\kirills.temcuks\Desktop\for macros"
Dim i As Long
'setting up the objTemplate var
Set objTemplate = objPowerPoint.Presentations.Open(fileName:=strTemplatePath)
'"saving as" ppt-template.
objTemplate.SaveAs fileName:=strSaveAs
'adding ppts marked with + in excel to the template.
'searching troug the rows from 2 to 6.
For i = 2 To 10 Step 1
If Cells(i, "B").Value <> "" Then
objTemplate.Slides.InsertFromFile fileName:=strWorkFolder & Cells(i, "B").Value, Index:=objTemplate.Slides.Count
End If
Next i
'complition message.
MsgBox "PPT completed", vbInformation
End Sub
I am super new to VBA, and already got stuck in completing one task. So if it is possible, please help me out with this one.
The idea is to merge all one-slider ppt presentations (all are in one folder) for corresponding person listed in the excel file. The challenge for me is that there is no strict ppt file name listed in excel worksheet only the name, id and e-mail for each person (e.g name listed in excel: "Iron Man", one-slider name for this person is: "Riga Marvel Iron Man.ppt").
So far I found a solution to merge ppt slide listed in excel if the value in the cell is 100% match to the ppt file name.
This is the example of excel table:
Nr. | Name | ID | |
1 | Iron Man | iron.man@something.com | iron.man |
2 | Spider Man | spider.man@something.com | spider.man |
3 | Wonder Woman | wonder.woman@something.com | wonder.woman |
4 | Green Lantern | green.lantern@something.com | green.lantern |
5 | Luke Cage | luke.cage@something.com | luke.cage |
<tbody>
</tbody>
Those are ppt files name:
Riga Marvel Wonder Woman.ppt
Riga Marvel Iron Man.ppt
Riga Marvel Green Lantern.ppt
Riga Marvel Spider Man.ppt
Riga Marvel Luke Cage.ppt
This is my code on the moment:
Sub Procedure1()
Dim objPowerPoint As Object
Dim objTemplate As Object
Set objPowerPoint = CreateObject(Class:="PowerPoint.Application")
'setting up the path to powerpoit template
Const strTemplatePath As String = "C:\Users\kirills.temcuks\Desktop\for macros\TEMPLATE.ppt"
'setting "save as" path.
Const strSaveAs As String = "C:\Users\kirills.temcuks\Desktop\TEMPLATE.ppt"
'setting path with "one-sliders.
Const strWorkFolder As String = "C:\Users\kirills.temcuks\Desktop\for macros"
Dim i As Long
'setting up the objTemplate var
Set objTemplate = objPowerPoint.Presentations.Open(fileName:=strTemplatePath)
'"saving as" ppt-template.
objTemplate.SaveAs fileName:=strSaveAs
'adding ppts marked with + in excel to the template.
'searching troug the rows from 2 to 6.
For i = 2 To 10 Step 1
If Cells(i, "B").Value <> "" Then
objTemplate.Slides.InsertFromFile fileName:=strWorkFolder & Cells(i, "B").Value, Index:=objTemplate.Slides.Count
End If
Next i
'complition message.
MsgBox "PPT completed", vbInformation
End Sub