【问题标题】:VBA Powerpoint to delete a TextBoxVBA Powerpoint 删除文本框
【发布时间】:2016-10-26 14:19:12
【问题描述】:

我想删除第一张幻灯片中的三个 TextBox。我写了这段代码,但它不起作用!! 这是我的代码:

Sub deleteTextBox()
Dim osld As Slide
Dim oShp As Shape
Dim oShp1 As Shape
Dim oShp2 As Shape
Set osld = ActivePresentation.Slides(1)
For Each oShp In osld.Shapes
If oShp.HasTextFrame Then
If oShp.Left = 20 And oShp.Top = 150 Then
oShp.Delete
End If
End If
Next oShp
For Each oShp1 In osld.Shapes
If oShp1.HasTextFrame Then
If oShp1.Left = 20 And oShp1.Top = 200 Then
oShp1.Delete
End If
End If
Next oShp1
For Each oShp2 In osld.Shapes
If oShp2.HasTextFrame Then
If oShp2.Left = 35 And oShp2.Top = 490 Then
oShp2.Delete
End If
End If
Next oShp2
End Sub

感谢您的帮助

【问题讨论】:

    标签: vba macros powerpoint


    【解决方案1】:

    您的形状是否完全按照代码中的值定位。您可以依次选择它们并在即时窗口中输入以下内容来检查:

    ?ActiveWindow.Selection.ShapeRange(1).Left
    
    ?ActiveWindow.Selection.ShapeRange(1).Top
    

    此外,您可以通过对形状进行一次循环并在每个形状上仅评估所有 3 个定位条件一次来优化代码。

    【讨论】:

    • 我通过循环形状找到了解决方案。谢谢杰米
    猜你喜欢
    • 1970-01-01
    • 2012-07-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-05
    • 2015-10-05
    相关资源
    最近更新 更多