【问题标题】:VBA character Font StyleVBA 字符字体样式
【发布时间】:2021-08-09 16:12:01
【问题描述】:
假装我有这样一句话:
“这是我的情况:”
":" 是常规的,我想改变它的样式,比如它之前的字符(E)。但我不知道在这种情况下使用哪个对象。我想找到“:”的索引,然后我检查它之前的字符字体样式(索引 - 1),如果它们不同,我会将字符“:”(索引)的字体样式更改为索引 - 1。
我尝试TextFrame.TextRange.Font,但出了点问题。
请帮助我,在此先感谢。
【问题讨论】:
标签:
vba
powerpoint
font-style
【解决方案1】:
试试这个代码:
Sub test()
Dim sh As Shape, EF As Font, textLen As Integer
For Each sh In ActivePresentation.Slides(1).Shapes
If sh.HasTextFrame Then
textLen = sh.TextFrame.TextRange.Length
If textLen > 1 Then
Set EF = sh.TextFrame.TextRange.Characters(textLen - 1, 1).Font
With sh.TextFrame.TextRange.Characters(textLen, 1).Font
.Name = EF.Name
.Color = EF.Color
.Size = EF.Size
.Italic = EF.Italic
.Bold = EF.Bold
.Underline = EF.Underline
' and other required properties
End With
End If
End If
Next
End Sub