Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Find the Name of a created control and delete it.

Status
Not open for further replies.

dtennis

Technical User
Sep 19, 2003
5
US
VBA on an Excel 2000 Worksheet

Using the following code I create a list box.

Set lstSubs = .Shapes.AddFormControl(xlListBox, 400, 700, 200, 200)

The next time someone opens this worksheet I want to make sure that this listbox is deleted so that when this code runs again it will not just keep putting one listbox on top of another. I am having problems finding the name of this listbox to delete the control.

Thanks
 
I'd suggest naming the control right after you create it:

Set lstSubs = .Shapes.AddFormControl(xlListBox, 400, 700, 200, 200)
lstSubs.Name = "MyName"

Then, use that name to delete the control in the Workbook_Open or the Workbook_BeforeClose events:

On error resume next ' in case it doesn't exist
Shapes("MyName").Delete
On error goto 0


Let me know if that helps!

VBAjedi [swords]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top