使用VBA删除所选列或范围中的所有文本框 [英] Using VBA to delete all text boxes in a selected column or range
问题描述
您好,我有一个不断复制文本框的宏,导致我的文件变慢。我可以用什么VBA代码删除列或特定范围内的所有文本框,例如(Cell F6到F1000)?
Hello, I have a macro that keeps copying text boxes and is causing my file to become slow. What VBA code can I use to delete all text boxes in a column or a specific range e.g (Cell F6 through F1000)?
推荐答案
什么类型的文本盒子?
What type of text boxes?
类型1: 通过选择开发者功能区创建 - >插入然后从ActiveX控件中选择。
Type 1: Created by selecting Developer ribbon -> Insert and then selecting from ActiveX controls.
类型2:通过选择插入功能区创建 - >文本框。
Type 2: Created by selecting Insert ribbon -> Text Boxes.
如果输入上面的代码1,则代码如下。请注意,您需要在运行代码之前选择要删除的范围。
If Type 1 above then following code. Note you need to select the range from which you want to delete before running the code.
Sub DeleteActiveXTextBoxes ()
Dim objCtrl As OLEObject
使用ActiveSheet
For Each objCtrl In .OLEObjects
如果没有相交(objCtrl.TopLeftCell,选择)没有那么
              &NBSP ;如果TypeName(objCtrl.Object)=" TextBox"然后是
objCtrl.Delete
结束如果
结束如果
下一个objCtrl
结束
Sub DeleteActiveXTextBoxes()
Dim objCtrl As OLEObject
With ActiveSheet
For Each objCtrl In .OLEObjects
If Not Intersect(objCtrl.TopLeftCell, Selection) Is Nothing Then
If TypeName(objCtrl.Object) = "TextBox" Then
objCtrl.Delete
End If
End If
Next objCtrl
End With
结束子
如果键入 2,则以下码。请注意,您需要在运行代码之前选择要删除的范围
If Type 2 above then following code. Note you need to select the range from which you want to delete before running the code
Sub DeleteMsoTextBoxes( )
Dim shp As Shape
Sub DeleteMsoTextBoxes()
Dim shp As Shape
使用ActiveSheet
对于每个shp In。形状
如果没有相交(shp.TopLeftCell,选择)没有那么
              &NBSP ;如果shp.Type = msoTextBox然后
                 &NBSP ;  shp.Delete
结束如果
结束如果
下一个shp
结束于$
结束子
With ActiveSheet
For Each shp In .Shapes
If Not Intersect(shp.TopLeftCell, Selection) Is Nothing Then
If shp.Type = msoTextBox Then
shp.Delete
End If
End If
Next shp
End With
End Sub
这篇关于使用VBA删除所选列或范围中的所有文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!