questiontoas
09-01-2014, 11:20 PM
Hi,
I am trying to replace a CURRENT TEXT with a new TEXT in various shape types in the slides, titlemaster and slidemaster of a number of open presentations. Unfortunately some shapes are not picked up. The reason could be
a) the master area contains yet another type (other than titlemaster and slidemaster)
b) I have not include the right shape type
c) other reasons I cannot think off.
Below is the script:
Sub Replace_Current_Text()
Dim sld As Slide
Dim grpItem As Shape
Dim shp As Shape
Dim ppt As Presentation
For Each ppt In Application.Presentations 'Loop through all open Presentations
If Not ppt Is Presentations("macro.pptm") Then 'Skip the Presentation that contains this macro
For Each sld In ppt.Slides 'Search all slide
For Each shp In sld.Shapes
If shp.HasTextFrame Then
If shp.TextFrame.HasText Then
shp.TextFrame.TextRange.Text = Replace(shp.TextFrame.TextRange.Text, "Current Text", "Next Text")
shp.TextFrame.TextRange.Text = Replace(shp.TextFrame.TextRange.Text, "CURRENT TEXT", "Next Text")
End If
If shp.Type = msoTextBox Then
shp.TextFrame.TextRange.Text = Replace(shp.TextFrame.TextRange.Text, "Current Text", "Next Text")
shp.TextFrame.TextRange.Text = Replace(shp.TextFrame.TextRange.Text, "CURRENT TEXT", "Next Text")
End If
If shp.Type = msoAutoShape Then
shp.TextFrame.TextRange.Text = Replace(shp.TextFrame.TextRange.Text, "Current Text", "Next Text")
shp.TextFrame.TextRange.Text = Replace(shp.TextFrame.TextRange.Text, "CURRENT TEXT", "Next Text")
End If
End If
Next
Next
For Each shp In ppt.TitleMaster.Shapes 'Search TitleMaster
If shp.TextFrame.HasText Then
shp.TextFrame.TextRange.Text = Replace(shp.TextFrame.TextRange.Text, "Current Text", "Next Text")
shp.TextFrame.TextRange.Text = Replace(shp.TextFrame.TextRange.Text, "CURRENT TEXT", "Next Text")
End If
If shp.Type = msoTextBox Then
shp.TextFrame.TextRange.Text = Replace(shp.TextFrame.TextRange.Text, "Current Text", "Next Text")
shp.TextFrame.TextRange.Text = Replace(shp.TextFrame.TextRange.Text, "CURRENT TEXT", "Next Text")
End If
If shp.Type = msoAutoShape Then
shp.TextFrame.TextRange.Text = Replace(shp.TextFrame.TextRange.Text, "Current Text", "Next Text")
shp.TextFrame.TextRange.Text = Replace(shp.TextFrame.TextRange.Text, "CURRENT TEXT", "Next Text")
End If
Next
For Each shp In ppt.SlideMaster.Shapes 'Search SlideMaster
If shp.TextFrame.HasText Then
shp.TextFrame.TextRange.Text = Replace(shp.TextFrame.TextRange.Text, "Current Text", "Next Text")
shp.TextFrame.TextRange.Text = Replace(shp.TextFrame.TextRange.Text, "CURRENT TEXT", "Next Text")
End If
If shp.Type = msoTextBox Then
shp.TextFrame.TextRange.Text = Replace(shp.TextFrame.TextRange.Text, "Current Text", "Next Text")
shp.TextFrame.TextRange.Text = Replace(shp.TextFrame.TextRange.Text, "CURRENT TEXT", "Next Text")
End If
If shp.Type = msoAutoShape Then
shp.TextFrame.TextRange.Text = Replace(shp.TextFrame.TextRange.Text, "Current Text", "Next Text")
shp.TextFrame.TextRange.Text = Replace(shp.TextFrame.TextRange.Text, "PROPRIETARY CURRENT TEXT", "Next Text")
End If
Next
End If
Next ppt
End Sub
Your help is appreciate for
a) Identifying any error in the script
b) advise how I could potentially identify the shape type in the SlideMaster / TitleMaster to check if I missed the right one
c) any other help.
Thanks a lot.
I am trying to replace a CURRENT TEXT with a new TEXT in various shape types in the slides, titlemaster and slidemaster of a number of open presentations. Unfortunately some shapes are not picked up. The reason could be
a) the master area contains yet another type (other than titlemaster and slidemaster)
b) I have not include the right shape type
c) other reasons I cannot think off.
Below is the script:
Sub Replace_Current_Text()
Dim sld As Slide
Dim grpItem As Shape
Dim shp As Shape
Dim ppt As Presentation
For Each ppt In Application.Presentations 'Loop through all open Presentations
If Not ppt Is Presentations("macro.pptm") Then 'Skip the Presentation that contains this macro
For Each sld In ppt.Slides 'Search all slide
For Each shp In sld.Shapes
If shp.HasTextFrame Then
If shp.TextFrame.HasText Then
shp.TextFrame.TextRange.Text = Replace(shp.TextFrame.TextRange.Text, "Current Text", "Next Text")
shp.TextFrame.TextRange.Text = Replace(shp.TextFrame.TextRange.Text, "CURRENT TEXT", "Next Text")
End If
If shp.Type = msoTextBox Then
shp.TextFrame.TextRange.Text = Replace(shp.TextFrame.TextRange.Text, "Current Text", "Next Text")
shp.TextFrame.TextRange.Text = Replace(shp.TextFrame.TextRange.Text, "CURRENT TEXT", "Next Text")
End If
If shp.Type = msoAutoShape Then
shp.TextFrame.TextRange.Text = Replace(shp.TextFrame.TextRange.Text, "Current Text", "Next Text")
shp.TextFrame.TextRange.Text = Replace(shp.TextFrame.TextRange.Text, "CURRENT TEXT", "Next Text")
End If
End If
Next
Next
For Each shp In ppt.TitleMaster.Shapes 'Search TitleMaster
If shp.TextFrame.HasText Then
shp.TextFrame.TextRange.Text = Replace(shp.TextFrame.TextRange.Text, "Current Text", "Next Text")
shp.TextFrame.TextRange.Text = Replace(shp.TextFrame.TextRange.Text, "CURRENT TEXT", "Next Text")
End If
If shp.Type = msoTextBox Then
shp.TextFrame.TextRange.Text = Replace(shp.TextFrame.TextRange.Text, "Current Text", "Next Text")
shp.TextFrame.TextRange.Text = Replace(shp.TextFrame.TextRange.Text, "CURRENT TEXT", "Next Text")
End If
If shp.Type = msoAutoShape Then
shp.TextFrame.TextRange.Text = Replace(shp.TextFrame.TextRange.Text, "Current Text", "Next Text")
shp.TextFrame.TextRange.Text = Replace(shp.TextFrame.TextRange.Text, "CURRENT TEXT", "Next Text")
End If
Next
For Each shp In ppt.SlideMaster.Shapes 'Search SlideMaster
If shp.TextFrame.HasText Then
shp.TextFrame.TextRange.Text = Replace(shp.TextFrame.TextRange.Text, "Current Text", "Next Text")
shp.TextFrame.TextRange.Text = Replace(shp.TextFrame.TextRange.Text, "CURRENT TEXT", "Next Text")
End If
If shp.Type = msoTextBox Then
shp.TextFrame.TextRange.Text = Replace(shp.TextFrame.TextRange.Text, "Current Text", "Next Text")
shp.TextFrame.TextRange.Text = Replace(shp.TextFrame.TextRange.Text, "CURRENT TEXT", "Next Text")
End If
If shp.Type = msoAutoShape Then
shp.TextFrame.TextRange.Text = Replace(shp.TextFrame.TextRange.Text, "Current Text", "Next Text")
shp.TextFrame.TextRange.Text = Replace(shp.TextFrame.TextRange.Text, "PROPRIETARY CURRENT TEXT", "Next Text")
End If
Next
End If
Next ppt
End Sub
Your help is appreciate for
a) Identifying any error in the script
b) advise how I could potentially identify the shape type in the SlideMaster / TitleMaster to check if I missed the right one
c) any other help.
Thanks a lot.