VBA Powerpoint删除TextBox

时间:2016-10-26 14:19:12

标签: vba macros powerpoint-vba

我想删除第一张幻灯片中的三个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

感谢您的帮助

1 个答案:

答案 0 :(得分:0)

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

?ActiveWindow.Selection.ShapeRange(1).Left

?ActiveWindow.Selection.ShapeRange(1).Top

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