替换Power Point中文本中特定字符的字体名称

时间:2013-07-12 06:59:11

标签: vba fonts powerpoint symbols powerpoint-vba

我想使用名为`

的字体查找并替换grave accent Rupee Forandian的所有实例

最近推出了卢比符号,没有键盘符号......

当我使用format函数尝试excel替换函数 CRTL + H 时,它会更改整个文本字符串的字体,而我希望它只更改严肃的口音`

我找到了Excel的解决方案,但我需要一个类似于Powerpoint 2007的解决方案。

Excel中使用的VBA是:

Sub InsertRupeeForandianSymbol()
  Dim X As Long, Cell As Range
  For Each Cell In Selection
    For X = 1 To Len(Cell.Value)
      If Mid(Cell.Value, X, 1) = "`" Then Cell.Characters(X, 1).Font.Name = "Rupee Foradian"
    Next
  Next
End Sub

2 个答案:

答案 0 :(得分:0)

在Powerpoint中,您必须遍历Shapes以获取文本:

Sub InsertRupeeForandianSymbol()
    Dim sl As Slide, sh As Shape, X As Long
    For Each sl In ActiveWindow.Selection.SlideRange
        For Each sh In sl.Shapes
            With sh.TextFrame.TextRange.Characters
                For X = 1 To .Count
                    If .Characters(X, 1).Text = "'" Then .Characters(X, 1).Font.Name = "Rupee Forandian"
                Next
            End With
        Next
    Next
End Sub

这将更改当前所有选定幻灯片的字体。您可以将ActiveWindow.Selection.SlideRange更改为ActivePresentation.Slides并应用于当前演示文稿中的所有幻灯片。

答案 1 :(得分:0)

我能想到的最简单的方法是

 Sub InsertRupeeForandianSymbol()
    Dim oSld As Slide
    Dim oShp As Shape
    Dim x As Long
    Dim y As Long

    For Each oSld In ActivePresentation.Slides
     For Each oShp In oSld.Shapes
         For y = 1 To Len(oShp.TextFrame.TextRange)
          If Mid(oShp.TextFrame.TextRange, y, 1) = "`" Then
            oShp.TextFrame.TextRange.Characters(y).Font.Name = "Rupee Foradian"
          End If
         Next y
     Next oShp
    Next oSld
End Sub