我想要将字符间距更改为段落中选定的文本。但我的以下代码更改了整个文本框的字符间距。有没有人能帮我。
例如,我只需要增加整个句子中选定文本的字符间距。如下图所示
ActiveWindow.Selection.ShapeRange.TextFrame2.TextRange.Font.Spacing = 3另外,下面的代码可以帮助我实现我的目的。但这里的问题是,我如何从宏中获得20和45。
ActiveWindow.Selection.ShapeRange.TextFrame2.TextRange.Characters(20, 45).Font.Spacing = 3

发布于 2020-08-07 02:15:27
你的代码:
ActiveWindow.Selection.ShapeRange.TextFrame2.TextRange.Font.Spacing = 3指选定形状的整个文本范围。取而代之的是:
ActiveWindow.Selection.TextRange2.Font.Spacing = 3这将仅作用于选定的文本。
发布于 2020-08-06 14:32:16
您需要遍历字符串并检查每个字母的字符字体格式,标记任何粗体文本部分的开始和结束,然后使用这些位置应用间距:
Dim shp As Shape, i As Long, pStart As Long, n As Long
Set shp = ActivePresentation.Slides(1).Shapes(1)
pStart = 0
With ActiveWindow.Selection.ShapeRange.TextFrame2.TextRange
n = .Characters.Count
For i = 1 To n
If .Characters(i, 1).Font.Bold Then
If pStart = 0 Then
pStart = i
ElseIf pStart > 0 And i = n Then 'ending on bold text
.Characters(pStart, i - pStart).Font.Spacing = 3
End If
Else
If pStart > 0 Then 'transitioning to non-bold
.Characters(pStart, i - pStart).Font.Spacing = 3
pStart = 0
End If
End If
Next i
End Withhttps://stackoverflow.com/questions/63277465
复制相似问题