如何阻止VBA PowerPoint脚本将整个文本框变为粗体。

时间:2017-08-31 23:24:47

标签: vba powerpoint powerpoint-vba

我有一个VBA脚本,可以在PowerPoint幻灯片中找到一个单词并替换它。它会在幻灯片上的每个文本框中搜索单词。一个文本框中没有单词,但有一些粗体文本。出于原因,当我运行脚本时,它会将该框中的所有文本变为粗体。

我可以输入一行代码来避免这种情况吗?

Sub ReplaceText()
Dim sld As Slide
Set sld = ActivePresentation.Slides(6)
Dim shp As Shape

For Each shp In sld.Shapes
    If shp.HasTextFrame Then
        If shp.TextFrame.HasText Then
            shp.TextFrame.TextRange.Text = Replace(shp.TextFrame.TextRange.Text, "Text1", ", NewText")
        End If
        If shp.TextFrame.HasText Then
            shp.TextFrame.TextRange.Text = Replace(shp.TextFrame.TextRange.Text, "Text2", "New Text, 2017")
        End If
        If shp.TextFrame.HasText Then
            shp.TextFrame.TextRange.Text = Replace(shp.TextFrame.TextRange.Text, "Text3", "New Text")
        End If
End If
Next shp
End Sub

0 个答案:

没有答案
相关问题