如何在PowerPoint VBA宏中将字符间距设置为紧缩0.5?
在PowerPoint VBA宏中设置字符间距为“紧缩0.5”的解决方案
完全可以实现你要的字符间距紧缩0.5的需求,问题出在Spacing属性的取值逻辑上——PowerPoint VBA里的TextRange.Font.Spacing属性,正值代表加宽字符间距,负值代表紧缩,你之前用的1是加宽1磅,自然达不到紧缩效果。
“紧缩0.5”对应的正确取值是-0.5,只需要在原有代码的格式设置部分添加这一行即可。修改后的完整代码如下:
Sub FormatText() Dim slide As slide Dim shape As shape Dim textRange As textRange ' 从第二张幻灯片开始遍历 For Each slide In ActivePresentation.Slides If slide.SlideIndex > 1 Then ' 遍历幻灯片中的每个形状 For Each shape In slide.Shapes If shape.HasTextFrame Then If shape.TextFrame.HasText Then For Each textRange In shape.TextFrame.textRange.Paragraphs If textRange.Font.Size = 70 Or textRange.Font.Size = 72 Then ' 应用格式设置 textRange.Font.Size = 72 textRange.ParagraphFormat.SpaceWithin = 0.85 ' 设置字符间距为紧缩0.5磅 textRange.Font.Spacing = -0.5 End If Next textRange End If End If Next shape End If Next slide End Sub
你可以根据需要微调Spacing的数值:比如-1对应紧缩1磅,1对应加宽1磅,数值的绝对值越大,间距调整幅度越明显。
内容的提问来源于stack exchange,提问作者Pink Shark
相关产品推荐
相关产品推荐

