|
|
|
|
|
|
Excel
|
Delete all ActiveX Controls from a sheet
|
|
Ease of Use
|
Easy
|
Version tested with
|
2000, 2002
|
Submitted by:
|
lucas
|
Description:
|
Allows you to delete all ActiveX Controls from the activesheet.
|
Discussion:
|
Occationally you wind up with a sheet littered with activeX controls. Comboboxes, etc and you wish to remove them all. Use this script to accomplish that task with the understanding that it does not work on controls created from the forms toolbar.
There is alternative code in the module for removing specific controls. The exampe shows how to remove just the ActiveX comboboxes from the active sheet.
|
Code:
|
instructions for use
|
Put this code In a standard module:
Option Explicit
Sub DeleteAllControls()
Dim obj As OLEObject
For Each obj In ActiveSheet.OLEObjects
obj.Delete
Next obj
End Sub
Sub DeleteComboboxesOnly()
Dim obj As OLEObject
For Each obj In ActiveSheet.OLEObjects
If obj.ProgId = "Forms.ComboBox.1" Then obj.Delete
Next obj
End Sub
|
How to use:
|
- Open the Visual Basic Editor by going to tools-Macro's-Visual Basic Editor or use Alt-F11
- On the toolbar of the Visual Basic Editor, go to insert - module
- In the module pane paste the code above.
- Close the Visual Basic Editor by clicking the X in the upper right corner or go to File-Close
|
Test the code:
|
- Place several controls on your worksheet from the controls toolbox.
- From the main menu select tools-Macro-Macros
- From the macros dialog box select the DeleteAllControls macro and click on Run
- If you wish to only remove comboboxes, select the DeleteComboboxesOnly macro.
|
Sample File:
|
Delete_ActiveX_Controls.zip 22.12KB
|
Approved by mdmackillop
|
This entry has been viewed 126 times.
|
|