如何使用 VBA 删除 PPT 中的多余空格? [英] How do I remove extra spaces in PPT using VBA?

查看:63
本文介绍了如何使用 VBA 删除 PPT 中的多余空格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能帮我看下面的代码?我正在尝试使用 VBA 删除 PowerPoint 演示文稿中的任何额外空格.

Can anyone help me with the below code? I am trying to use VBA to remove any extra spaces in a PowerPoint presentation.

Sub removeSpaces()
Dim sld As Slide
Dim shp As Shape
For Each sld In ActivePresentation.Slides
    For Each shp In sld.Shapes
    Do While InStr(shp, "  ") > 0
        shp.Value = Replace(shp, "  ", " ")
        shp.Value = Trim(shp.Value)
    Next shp
Next sld
End Sub

当我当前运行它时,它显示未找到方法或数据成员"的错误并突出显示shp.Value"部分.

When I currently run it, it shows an error of "Method or data member not found" and highlights the "shp.Value" part.

推荐答案

Shape 对象没有 .Value 属性.Instr 函数也可能不会针对 Shape 对象进行评估.

a Shape object doesn't have a .Value property. The Instr function may also not evaluate against a Shape object.

https://msdn.microsoft.com/en-us/library/office/ff747227(v=office.14).aspx

一般需要参考shape的TextFrame,比如:

Generally, you need to refer to the shape's TextFrame, like:

Dim shpText as String

For Each sld In ActivePresentation.Slides
    For Each shp In sld.Shapes
        If shp.HasTextFrame Then
            shpText = shp.TextFrame.TextRange.Text 'Get the shape's text
            Do While InStr(shpText, "  ") > 0
                shpText = Trim(Replace(shpText, "  ", " "))
            Loop
            shp.TextFrame.TextRange.Text = shpText 'Put the new text in the shape
        Else
            shpText = vbNullString
        End If
    Next shp    
Next sld
End Sub

这篇关于如何使用 VBA 删除 PPT 中的多余空格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆