Rosenrot
01-06-2017, 05:20 PM
Hi everyone,
The aim of the code below was to insert hard spaces before certain words so that they automatically jump into the next line. The problem is that when a shape contains some words in bold, the VBA code turns off this particular formatting.
Do you have any idea how to improve the code so that it preserves the text formatting? Thank you in advance!
Sub NextLine()
Dim oSld As Slide
Dim oShp As Shape
With ActivePresentation
For Each oSld In .Slides
For Each oShp In oSld.Shapes
If oShp.HasTextFrame Then
If oShp.TextFrame.HasText Then
oShp.TextFrame.TextRange.Text = Replace(oShp.TextFrame.TextRange.Text, "and" & Chr$(32), "and" & Chr$(160))
oShp.TextFrame.TextRange.Text = Replace(oShp.TextFrame.TextRange.Text, "or" & Chr$(32), "or" & Chr$(160))
End If
End If
Next
Next
End With
End Sub
The aim of the code below was to insert hard spaces before certain words so that they automatically jump into the next line. The problem is that when a shape contains some words in bold, the VBA code turns off this particular formatting.
Do you have any idea how to improve the code so that it preserves the text formatting? Thank you in advance!
Sub NextLine()
Dim oSld As Slide
Dim oShp As Shape
With ActivePresentation
For Each oSld In .Slides
For Each oShp In oSld.Shapes
If oShp.HasTextFrame Then
If oShp.TextFrame.HasText Then
oShp.TextFrame.TextRange.Text = Replace(oShp.TextFrame.TextRange.Text, "and" & Chr$(32), "and" & Chr$(160))
oShp.TextFrame.TextRange.Text = Replace(oShp.TextFrame.TextRange.Text, "or" & Chr$(32), "or" & Chr$(160))
End If
End If
Next
Next
End With
End Sub