noslenwerd
Board Regular
- Joined
- Nov 12, 2019
- Messages
- 85
- Office Version
- 365
I found this bit of code on the forums, and it does a great job of replacing the first instance of a tag, but does not replace the second.
For instance if I have <<customername>> in the PPT, I have a cell with John Doe in Excel that overwrites that tag.
But if I have a second instance of <<customername>> in the PPT, it does not get replaced.
Is there any way to do that via VBA?
My code below:
For instance if I have <<customername>> in the PPT, I have a cell with John Doe in Excel that overwrites that tag.
But if I have a second instance of <<customername>> in the PPT, it does not get replaced.
Is there any way to do that via VBA?
My code below:
VBA Code:
'**********************START PPT COVER SLIDE POPULATION
With ThisWorkbook.Sheets("PPTRecapData")
'PROMPT USER TO OPEN POWERPOINT DOC
Set objPPT = CreateObject("PowerPoint.Application")
objPPT.Visible = True
'PULLING ARRAY FROM EXCEL
FindArray = Application.Transpose(ThisWorkbook.Worksheets("PPTRecapData").Range("A2:A13"))
ReplaceArray = Application.Transpose(ThisWorkbook.Worksheets("PPTRecapData").Range("B2:B13"))
'LOOP THROUGH EACH SLIDE
For Each sld In objPPT.ActivePresentation.Slides
objPPT.Activate
objPPT.ActiveWindow.View.GotoSlide sld.SlideIndex
For Y = LBound(FindArray) To UBound(FindArray)
For Each shp In sld.Shapes
fnd = FindArray(Y)
rplc = ReplaceArray(Y)
If shp.HasTextFrame Then
If shp.TextFrame.HasText Then
Set TxtRng = shp.TextFrame.TextRange.Find(fnd, 0, True, WholeWords:=msoFalse)
If TxtRng Is Nothing Then GoTo NextTxtRng
TxtRng.Select
Set TmpRng = TxtRng.Replace(FindWhat:=fnd, _
ReplaceWhat:=rplc, WholeWords:=False, MatchCase:=True)
End If
End If
'THIS IS THE CODE THAT WAS SUPPOSED TO REPLACE EXTRA INSTANCES
Do While Not TmpRng Is Nothing
Set TmpRng = TxtRng.Replace(FindWhat:=fnd, _
ReplaceWhat:=rplc, WholeWords:=False, MatchCase:=False)
Loop
'IF TEXT RANGE IS NOTHING (NO VALUE FOUND)
NextTxtRng:
Next shp
Next Y
Next sld
AppActivate Application.Caption
MsgBox "Cover Page Population Done!"
'IF NO POWERPOINT SELECTED
Ending:
End With
'**********************END PPT COVER SLIDE POPULATION