Hi, I used to work with macros but don't know vba, I just used to record them. I am trying to set up a macro to create powerpoints automatically from excel sheets. I have downloaded a sample one from a forum which creates two text boxes from two columns in the excel. I would like to also add an image box - a different image on each slide. I don't think I can add images to hte excel - or can I? I can add pathways to the images, but how would I tell the macro to convert that pathway to the image itself? Or is there a better way to do it? This is the macro I have downloaded thanks to a site called contextures. Thank you for your help!
VBA Code:
Option Explicit
Sub CreateSlidesTest_Text1()
'https://www.contextures.com
'create slide for names
' that pass criteria test
'fill one text box
Dim myPT As Presentation
Dim xlApp As Object
Dim wbA As Object
Dim wsA As Object
Dim myList As Object
Dim myRng As Object
Dim i As Long
Dim col01 As Long
Dim colTest As Long
Dim strTest As String
'column with text for slides
col01 = 1
'test column and criterion
colTest = 3
strTest = "y"
On Error Resume Next
Set myPT = ActivePresentation
Set xlApp = GetObject(, "Excel.Application")
Set wbA = xlApp.ActiveWorkbook
Set wsA = wbA.ActiveSheet
Set myList = wsA.ListObjects(1)
On Error GoTo errHandler
If Not myList Is Nothing Then
Set myRng = myList.DataBodyRange
For i = 1 To myRng.Rows.Count
'Copy first slide, paste after last slide
If UCase(myRng.Cells(i, colTest).Value) _
= UCase(strTest) Then
With myPT
.Slides(1).Copy
.Slides.Paste (myPT.Slides.Count + 1)
'change text in 1st textbox
.Slides(.Slides.Count) _
.Shapes(1).TextFrame.TextRange.Text _
= myRng.Cells(i, col01).Value
End With
End If
Next
Else
MsgBox "No Excel table found on active sheet"
GoTo exitHandler
End If
exitHandler:
Exit Sub
errHandler:
MsgBox "Could not complete slides"
Resume exitHandler:
End Sub
Sub CreateSlidesTest_Text2()
'https://www.contextures.com
'create slide for names
' that pass criteria test
'fill two text boxes
Dim myPT As Presentation
Dim xlApp As Object
Dim wbA As Object
Dim wsA As Object
Dim myList As Object
Dim myRng As Object
Dim i As Long
Dim col01 As Long
Dim col02 As Long
Dim colTest As Long
Dim strTest As String
'columns with text for slides
col01 = 1
col02 = 2
'test column and criterion
colTest = 3
strTest = "y"
On Error Resume Next
Set myPT = ActivePresentation
Set xlApp = GetObject(, "Excel.Application")
Set wbA = xlApp.ActiveWorkbook
Set wsA = wbA.ActiveSheet
Set myList = wsA.ListObjects(1)
On Error GoTo errHandler
If Not myList Is Nothing Then
Set myRng = myList.DataBodyRange
For i = 1 To myRng.Rows.Count
'Copy first slide, paste after last slide
If UCase(myRng.Cells(i, colTest).Value) _
= UCase(strTest) Then
With myPT
.Slides(1).Copy
.Slides.Paste (myPT.Slides.Count + 1)
'change text in 1st textbox
.Slides(.Slides.Count) _
.Shapes(1).TextFrame.TextRange.Text _
= myRng.Cells(i, col01).Value
'change text in 2nd textbox
.Slides(.Slides.Count) _
.Shapes(2).TextFrame.TextRange.Text _
= myRng.Cells(i, col02).Value
End With
End If
Next
Else
MsgBox "No Excel table found on active sheet"
GoTo exitHandler
End If
exitHandler:
Exit Sub
errHandler:
MsgBox "Could not complete slides"
Resume exitHandler:
End Sub