Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Dynamic controls

Hi,

I wonder if someone can point me in the right direction. I need to create a
variable number of combo boxes dynamically in a spread sheet, taking their
contents from sets of other spreadsheets.

Set cb = ActiveWorkbook.Sheets(1).OLEObjects.Add("Forms.com bobox.1",
Left:=c.Left, Top:=c.Top, Height:=c.Height, Width:=c.Width)
(where c is the cell)

That part is fine, the first time the combo boxes are created.

The user selects from another combo box (design time added) to select
another set of spreadsheets to use to populate the dynamic ones.
The problem is when I want to re-create the page, I need to first delete the
current combo boxes before I create the new ones. How do I reference the
existing combo boxes? I can't add a Name reference to the Add method and I
can't seem to define the name after the combo box has been created (cb.name
= "ComboList1") so end up with the default one of combobox1, combobox2 etc.

If I simply loop through the Shapes collection (for each sh in Shapes), then
I don't seem to be able to distinguish between the design-time-added combo
and the dynamic ones even though they have markedly different names.
(cbxCategories vs comboboxn)

TIA
Martin


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Dynamic controls

Hi
You could try something like this

Dim cb As Shape
On Error Resume Next
For Each cb In ActiveSheet.Shapes
If cb.Name Like "ComboBox*" Then
cb.Delete
End If
Next

;-)

Martin Walke wrote in message
...
Hi,

I wonder if someone can point me in the right direction. I need to create

a
variable number of combo boxes dynamically in a spread sheet, taking their
contents from sets of other spreadsheets.

Set cb = ActiveWorkbook.Sheets(1).OLEObjects.Add("Forms.com bobox.1",
Left:=c.Left, Top:=c.Top, Height:=c.Height, Width:=c.Width)
(where c is the cell)

That part is fine, the first time the combo boxes are created.

The user selects from another combo box (design time added) to select
another set of spreadsheets to use to populate the dynamic ones.
The problem is when I want to re-create the page, I need to first delete

the
current combo boxes before I create the new ones. How do I reference the
existing combo boxes? I can't add a Name reference to the Add method and I
can't seem to define the name after the combo box has been created

(cb.name
= "ComboList1") so end up with the default one of combobox1, combobox2

etc.

If I simply loop through the Shapes collection (for each sh in Shapes),

then
I don't seem to be able to distinguish between the design-time-added combo
and the dynamic ones even though they have markedly different names.
(cbxCategories vs comboboxn)

TIA
Martin




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Dynamic controls

Thanks Loomah for the quick reply.

I have tried exactly that (almost) but the problem is that the
design-time-added combo has the *same* name as the first dynamically added
one. It seems bizarre to have two controls with the same name. Is there any
other way of distinguishing between two controls, particularly ones that
have been added at design time and ones that have been added dynamically?

BTW, why's the On error statement there?

Martin

"Loomah" <bellm AT globalnet dot co dot uk wrote in message
...
Hi
You could try something like this

Dim cb As Shape
On Error Resume Next
For Each cb In ActiveSheet.Shapes
If cb.Name Like "ComboBox*" Then
cb.Delete
End If
Next

;-)

Martin Walke wrote in message
...
Hi,

I wonder if someone can point me in the right direction. I need to

create
a
variable number of combo boxes dynamically in a spread sheet, taking

their
contents from sets of other spreadsheets.

Set cb = ActiveWorkbook.Sheets(1).OLEObjects.Add("Forms.com bobox.1",
Left:=c.Left, Top:=c.Top, Height:=c.Height, Width:=c.Width)
(where c is the cell)

That part is fine, the first time the combo boxes are created.

The user selects from another combo box (design time added) to select
another set of spreadsheets to use to populate the dynamic ones.
The problem is when I want to re-create the page, I need to first delete

the
current combo boxes before I create the new ones. How do I reference the
existing combo boxes? I can't add a Name reference to the Add method and

I
can't seem to define the name after the combo box has been created

(cb.name
= "ComboList1") so end up with the default one of combobox1, combobox2

etc.

If I simply loop through the Shapes collection (for each sh in Shapes),

then
I don't seem to be able to distinguish between the design-time-added

combo
and the dynamic ones even though they have markedly different names.
(cbxCategories vs comboboxn)

TIA
Martin







  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Dynamic controls

Martin
I don't know of any way to distinguish between design & run time created
controls - that doesn't mean there isn't a way!
There's probably some reason for this but why can't you change the name of
the control(s) created at design time to allow the code to work with the
default names of those created at run time?

The On Error statement is (was) there as I was having problems stepping thru
the code. It isn't necessary - apart from the fact that there should always
be some sort of error handling in code.

Martin Walke wrote in message
...
Thanks Loomah for the quick reply.

I have tried exactly that (almost) but the problem is that the
design-time-added combo has the *same* name as the first dynamically added
one. It seems bizarre to have two controls with the same name. Is there

any
other way of distinguishing between two controls, particularly ones that
have been added at design time and ones that have been added dynamically?

BTW, why's the On error statement there?

Martin

"Loomah" <bellm AT globalnet dot co dot uk wrote in message
...
Hi
You could try something like this

Dim cb As Shape
On Error Resume Next
For Each cb In ActiveSheet.Shapes
If cb.Name Like "ComboBox*" Then
cb.Delete
End If
Next

;-)

Martin Walke wrote in message
...
Hi,

I wonder if someone can point me in the right direction. I need to

create
a
variable number of combo boxes dynamically in a spread sheet, taking

their
contents from sets of other spreadsheets.

Set cb = ActiveWorkbook.Sheets(1).OLEObjects.Add("Forms.com bobox.1",
Left:=c.Left, Top:=c.Top, Height:=c.Height, Width:=c.Width)
(where c is the cell)

That part is fine, the first time the combo boxes are created.

The user selects from another combo box (design time added) to select
another set of spreadsheets to use to populate the dynamic ones.
The problem is when I want to re-create the page, I need to first

delete
the
current combo boxes before I create the new ones. How do I reference

the
existing combo boxes? I can't add a Name reference to the Add method

and
I
can't seem to define the name after the combo box has been created

(cb.name
= "ComboList1") so end up with the default one of combobox1, combobox2

etc.

If I simply loop through the Shapes collection (for each sh in

Shapes),
then
I don't seem to be able to distinguish between the design-time-added

combo
and the dynamic ones even though they have markedly different names.
(cbxCategories vs comboboxn)

TIA
Martin









  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Dynamic controls

You misunderstand me (or I haven't made myself clear :-).

The design time control is named (via the properties), cbxCategories. The
dynamic ones, via the Add method, are named ComboBox1, ComboBox2 etc.

However, when I reference them at the runtime, the cbxCategories reports
that its name is ComboBox1 (!) and that the first dynamic one is *also*
ComboBox1 so if I then try and delete the control named ComboBox1 it deletes
the wrong one!

But there appears to be light at the end of the tunnel! I was using
cb.object.name to name the control but have since rationalised my code with
functions etc and can now use cb.name which the control appears to 'know'
and understand.

Let me experiment a bit more.

Martin

"Loomah" <bellm AT globalnet dot co dot uk wrote in message
...
Martin
I don't know of any way to distinguish between design & run time created
controls - that doesn't mean there isn't a way!
There's probably some reason for this but why can't you change the name of
the control(s) created at design time to allow the code to work with the
default names of those created at run time?

The On Error statement is (was) there as I was having problems stepping

thru
the code. It isn't necessary - apart from the fact that there should

always
be some sort of error handling in code.

Martin Walke wrote in message
...
Thanks Loomah for the quick reply.

I have tried exactly that (almost) but the problem is that the
design-time-added combo has the *same* name as the first dynamically

added
one. It seems bizarre to have two controls with the same name. Is there

any
other way of distinguishing between two controls, particularly ones that
have been added at design time and ones that have been added

dynamically?

BTW, why's the On error statement there?

Martin

"Loomah" <bellm AT globalnet dot co dot uk wrote in message
...
Hi
You could try something like this

Dim cb As Shape
On Error Resume Next
For Each cb In ActiveSheet.Shapes
If cb.Name Like "ComboBox*" Then
cb.Delete
End If
Next

;-)

Martin Walke wrote in message
...
Hi,

I wonder if someone can point me in the right direction. I need to

create
a
variable number of combo boxes dynamically in a spread sheet, taking

their
contents from sets of other spreadsheets.

Set cb =

ActiveWorkbook.Sheets(1).OLEObjects.Add("Forms.com bobox.1",
Left:=c.Left, Top:=c.Top, Height:=c.Height, Width:=c.Width)
(where c is the cell)

That part is fine, the first time the combo boxes are created.

The user selects from another combo box (design time added) to

select
another set of spreadsheets to use to populate the dynamic ones.
The problem is when I want to re-create the page, I need to first

delete
the
current combo boxes before I create the new ones. How do I reference

the
existing combo boxes? I can't add a Name reference to the Add method

and
I
can't seem to define the name after the combo box has been created
(cb.name
= "ComboList1") so end up with the default one of combobox1,

combobox2
etc.

If I simply loop through the Shapes collection (for each sh in

Shapes),
then
I don't seem to be able to distinguish between the design-time-added

combo
and the dynamic ones even though they have markedly different names.
(cbxCategories vs comboboxn)

TIA
Martin













  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Dynamic controls

Loomah,

It's sorted!! I'm not 100% sure what happened to make things right but
having now been able to name the controls to something totally different and
name them in a different part of code seems to have sorted it out.

It may have been the way I was referencing the controls as objects. I do
sometimes get very confused about which/what/where although it seems simple
enough when you stand back!!

Thanks again for being a sounding board if nothing else

Martin

"Loomah" <bellm AT globalnet dot co dot uk wrote in message
...
Martin
I don't know of any way to distinguish between design & run time created
controls - that doesn't mean there isn't a way!
There's probably some reason for this but why can't you change the name of
the control(s) created at design time to allow the code to work with the
default names of those created at run time?

The On Error statement is (was) there as I was having problems stepping

thru
the code. It isn't necessary - apart from the fact that there should

always
be some sort of error handling in code.

Martin Walke wrote in message
...
Thanks Loomah for the quick reply.

I have tried exactly that (almost) but the problem is that the
design-time-added combo has the *same* name as the first dynamically

added
one. It seems bizarre to have two controls with the same name. Is there

any
other way of distinguishing between two controls, particularly ones that
have been added at design time and ones that have been added

dynamically?

BTW, why's the On error statement there?

Martin

"Loomah" <bellm AT globalnet dot co dot uk wrote in message
...
Hi
You could try something like this

Dim cb As Shape
On Error Resume Next
For Each cb In ActiveSheet.Shapes
If cb.Name Like "ComboBox*" Then
cb.Delete
End If
Next

;-)

Martin Walke wrote in message
...
Hi,

I wonder if someone can point me in the right direction. I need to

create
a
variable number of combo boxes dynamically in a spread sheet, taking

their
contents from sets of other spreadsheets.

Set cb =

ActiveWorkbook.Sheets(1).OLEObjects.Add("Forms.com bobox.1",
Left:=c.Left, Top:=c.Top, Height:=c.Height, Width:=c.Width)
(where c is the cell)

That part is fine, the first time the combo boxes are created.

The user selects from another combo box (design time added) to

select
another set of spreadsheets to use to populate the dynamic ones.
The problem is when I want to re-create the page, I need to first

delete
the
current combo boxes before I create the new ones. How do I reference

the
existing combo boxes? I can't add a Name reference to the Add method

and
I
can't seem to define the name after the combo box has been created
(cb.name
= "ComboList1") so end up with the default one of combobox1,

combobox2
etc.

If I simply loop through the Shapes collection (for each sh in

Shapes),
then
I don't seem to be able to distinguish between the design-time-added

combo
and the dynamic ones even though they have markedly different names.
(cbxCategories vs comboboxn)

TIA
Martin











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
Help with copying dynamic column selected based on remote cell value and dynamic formula fill ers Charts and Charting in Excel 0 March 1st 06 01:05 AM
Dynamic Range with unused formula messing up x axis on dynamic graph [email protected] Charts and Charting in Excel 2 February 2nd 06 08:02 PM
ActiveX Controls vs Form Controls Alex Excel Discussion (Misc queries) 1 January 11th 06 08:46 AM
creating dynamic controls monika Excel Programming 0 April 1st 04 01:56 AM
Dynamic Label for Controls Rob Bovey Excel Programming 0 September 8th 03 06:47 PM


All times are GMT +1. The time now is 06:12 AM.

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"