VBA程序 在PPT中使用宏命令删除空白的文本框

打开PPT,切换到视图菜单下,点击宏,输入宏的名称(如clear),点击创建。进入命令窗口,复制以下命令编译执行即可。

Sub clear()
Dim found As Boolean
Dim textflag As Boolean
Dim trng As TextRange
Do
found = False
For Each Sld In ActivePresentation.Slides
    For Each shp In Sld.Shapes
     If shp.HasTextFrame Then
        textflag = False
        If shp.TextFrame.HasText Then
        Set trng = shp.TextFrame.TextRange
            For i = trng.Characters.Count To 1 Step -1
            If trng.Characters(i) <> " " Then
                textflag = True
                Exit For
            End If
            Next
         End If
         If shp.Type <> 1 Then
            If Not shp.TextFrame.HasText Or textflag = False Then
            ActiveWindow.View.GotoSlide Index:=shp.Parent.SlideIndex
            shp.Select
            shp.Delete
            found = True
            End If
         End If
    End If
    Next shp
Next Sld
Loop While found = True
End Sub

注意:上面的宏名称是clear,可以改成自己喜欢的名字。