View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
[email protected] david.j.winfield@gmail.com is offline
external usenet poster
 
Posts: 25
Default Programmatically create a label in a worksheet.

On Apr 1, 9:29 am, Ivyleaf wrote:
Hi David,

Depends what sort of label you mean... one from the 'control toolbox'
or 'forms' bar. They both have their pro's and cons. Personally I
usually prefer the 'forms' ones. To add one of these, the following
code should be an example:

Sub MakeLabels()
Dim myLabel As Label
Dim TgtRng As Range

Set TgtRng = Selection

With TgtRng
Set myLabel =
ActiveSheet.Labels.Add(.Left, .Top, .Width, .Height)
End With
With myLabel
.Caption = "Helo world... I'm a label!"
.Name = "New Label"
End With
End Sub

As for making an array of them, I don't think you can... but you could
possibly stick 'em in a collection? I've never tried it. Someone else
on here is bound to know.

Cheers,
Ivan.

On Apr 2, 12:01 am, "

wrote:
I am using excel 2003. How would I programmatically create a label in
a worksheet. The following doesn't work:
Dim mylabel As Label
mylabel.Visible = True
mylabel.Caption = "my caption"


Is there a way to programmatically create an array of labels by doing
Dim mylabels(5) as label?


Then could I create/delete the label as needed by using mylabel.create
(or whatever the appropriate method is) and mylabel.delete?


if I want a new function that performs an action on several different
labels can I give it a label/array of labels as a parameter by
declaring the function with something like:
Function my_label_function(changelabel as label) as integer


Thanks,
David


Thank you, this works great. How would I make a label of the type
that is on the 'control toolbox'?