Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default Delete ComboBoxes using a macro?

I need to delete 33 Comboxes all on the same sheet by using a macro. I am
using very simple code as below, which I got from recording a macro and
deleting one ComboBox which worked fine.

ActiveSheet.Shapes("ComboBox1").Select
Selection.Delete
ActiveSheet.Shapes("ComboBox2").Select
Selection.Delete
ActiveSheet.Shapes("ComboBox3").Select
Selection.Delete

And so on until I have deleted all 33. My problem is that I get an error
message stating:

Run-Time error '-2147024809 (80070057)
The item with the specified name wasn't found.

I have checked the properties of the boxes and they appear to be "named"
correctly. However, if I use On Error Resume Next all but two are deleted.

Any help and advice would be much appreciated as it's driving me "NUTS".

--
Kind Regards

Mick


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Delete ComboBoxes using a macro?

Assuming comboboxes from the Control Toolbox Toolbar

Dim obj as OleObject
for each obj in Activesheet.OleObjects
if typeof obj.Object is MSForms.Combobox then
obj.Delete
end if
Next

--
Regards,
Tom Ogilvy

"Grandad" wrote in message
...
I need to delete 33 Comboxes all on the same sheet by using a macro. I am
using very simple code as below, which I got from recording a macro and
deleting one ComboBox which worked fine.

ActiveSheet.Shapes("ComboBox1").Select
Selection.Delete
ActiveSheet.Shapes("ComboBox2").Select
Selection.Delete
ActiveSheet.Shapes("ComboBox3").Select
Selection.Delete

And so on until I have deleted all 33. My problem is that I get an error
message stating:

Run-Time error '-2147024809 (80070057)
The item with the specified name wasn't found.

I have checked the properties of the boxes and they appear to be "named"
correctly. However, if I use On Error Resume Next all but two are

deleted.

Any help and advice would be much appreciated as it's driving me "NUTS".

--
Kind Regards

Mick




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default Delete ComboBoxes using a macro?

Tom

Thanks, unfortunately I get a run-time error '438': Object doesn't support
this property or method, when it gets to "for each obj in
Activesheet.OleObjects"

Thanks

Mick

"Tom Ogilvy" wrote in message
...
Assuming comboboxes from the Control Toolbox Toolbar

Dim obj as OleObject
for each obj in Activesheet.OleObjects
if typeof obj.Object is MSForms.Combobox then
obj.Delete
end if
Next

--
Regards,
Tom Ogilvy

"Grandad" wrote in message
...
I need to delete 33 Comboxes all on the same sheet by using a macro. I
am
using very simple code as below, which I got from recording a macro and
deleting one ComboBox which worked fine.

ActiveSheet.Shapes("ComboBox1").Select
Selection.Delete
ActiveSheet.Shapes("ComboBox2").Select
Selection.Delete
ActiveSheet.Shapes("ComboBox3").Select
Selection.Delete

And so on until I have deleted all 33. My problem is that I get an error
message stating:

Run-Time error '-2147024809 (80070057)
The item with the specified name wasn't found.

I have checked the properties of the boxes and they appear to be "named"
correctly. However, if I use On Error Resume Next all but two are

deleted.

Any help and advice would be much appreciated as it's driving me "NUTS".

--
Kind Regards

Mick






  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Delete ComboBoxes using a macro?

In a general module, this deleted all the comboboxes from the control
toolbox toolbar:

Sub Tester9()
Dim obj As OLEObject
For Each obj In ActiveSheet.OLEObjects
If TypeOf obj.Object Is MSForms.ComboBox Then
obj.Delete
End If
Next

End Sub

You can replace ActiveSheet with something Worksheets("Sheet1") if that is
where your comboboxes are located.

If you have dropdowns from the Forms toolbar

ActiveSheet.DropDowns.Delete

These are proven methods used successfully hundreds of times. If they don't
work for you, then you are probably in a sheet module or have some other
type of referencing problem.

--
Regards,
Tom Ogilvy



"Grandad" wrote in message
...
Tom

Thanks, unfortunately I get a run-time error '438': Object doesn't support
this property or method, when it gets to "for each obj in
Activesheet.OleObjects"

Thanks

Mick

"Tom Ogilvy" wrote in message
...
Assuming comboboxes from the Control Toolbox Toolbar

Dim obj as OleObject
for each obj in Activesheet.OleObjects
if typeof obj.Object is MSForms.Combobox then
obj.Delete
end if
Next

--
Regards,
Tom Ogilvy

"Grandad" wrote in message
...
I need to delete 33 Comboxes all on the same sheet by using a macro. I
am
using very simple code as below, which I got from recording a macro and
deleting one ComboBox which worked fine.

ActiveSheet.Shapes("ComboBox1").Select
Selection.Delete
ActiveSheet.Shapes("ComboBox2").Select
Selection.Delete
ActiveSheet.Shapes("ComboBox3").Select
Selection.Delete

And so on until I have deleted all 33. My problem is that I get an

error
message stating:

Run-Time error '-2147024809 (80070057)
The item with the specified name wasn't found.

I have checked the properties of the boxes and they appear to be

"named"
correctly. However, if I use On Error Resume Next all but two are

deleted.

Any help and advice would be much appreciated as it's driving me

"NUTS".

--
Kind Regards

Mick








  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default Delete ComboBoxes using a macro?

Tom

Thanks for your help, it turned out that I had missed the "S" of the end of
OLEObjects

Regards

Mick

"Tom Ogilvy" wrote in message
...
In a general module, this deleted all the comboboxes from the control
toolbox toolbar:

Sub Tester9()
Dim obj As OLEObject
For Each obj In ActiveSheet.OLEObjects
If TypeOf obj.Object Is MSForms.ComboBox Then
obj.Delete
End If
Next

End Sub

You can replace ActiveSheet with something Worksheets("Sheet1") if that
is
where your comboboxes are located.

If you have dropdowns from the Forms toolbar

ActiveSheet.DropDowns.Delete

These are proven methods used successfully hundreds of times. If they
don't
work for you, then you are probably in a sheet module or have some other
type of referencing problem.

--
Regards,
Tom Ogilvy



"Grandad" wrote in message
...
Tom

Thanks, unfortunately I get a run-time error '438': Object doesn't
support
this property or method, when it gets to "for each obj in
Activesheet.OleObjects"

Thanks

Mick

"Tom Ogilvy" wrote in message
...
Assuming comboboxes from the Control Toolbox Toolbar

Dim obj as OleObject
for each obj in Activesheet.OleObjects
if typeof obj.Object is MSForms.Combobox then
obj.Delete
end if
Next

--
Regards,
Tom Ogilvy

"Grandad" wrote in message
...
I need to delete 33 Comboxes all on the same sheet by using a macro.
I
am
using very simple code as below, which I got from recording a macro
and
deleting one ComboBox which worked fine.

ActiveSheet.Shapes("ComboBox1").Select
Selection.Delete
ActiveSheet.Shapes("ComboBox2").Select
Selection.Delete
ActiveSheet.Shapes("ComboBox3").Select
Selection.Delete

And so on until I have deleted all 33. My problem is that I get an

error
message stating:

Run-Time error '-2147024809 (80070057)
The item with the specified name wasn't found.

I have checked the properties of the boxes and they appear to be

"named"
correctly. However, if I use On Error Resume Next all but two are
deleted.

Any help and advice would be much appreciated as it's driving me

"NUTS".

--
Kind Regards

Mick










Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How can I delete a macro when the Delete button is not active? FCR Excel Worksheet Functions 0 March 9th 06 09:43 AM
How do i delete a macro in Excel 2003 when delete isn't highlight Abel Excel Discussion (Misc queries) 2 September 13th 05 04:09 AM
Need help with ComboBoxes. rosemary New Users to Excel 2 July 9th 05 12:19 AM
macro to delete entire rows when column A is blank ...a quick macro vikram Excel Programming 4 May 3rd 04 08:45 PM
Comboboxes Angeliki Excel Programming 1 March 3rd 04 12:00 PM


All times are GMT +1. The time now is 01:58 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"