VBA to capture active userform label caption

Trebor76

Well-known Member
Joined
Jul 23, 2007
Messages
5,363
Office Version
  1. 365
Platform
  1. Windows
Hi there,

I've been struggling with this for hours, which (in my mind anyway), should be an easy one.

All I want to do is set a string variable with the active label’s (i.e. just clicked) userform caption. The label is a form control not an ActiveX control.

Hope someone can help.

Regards,

Robert
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Hi there,

I've been struggling with this for hours, which (in my mind anyway), should be an easy one.

All I want to do is set a string variable with the active label’s (i.e. just clicked) userform caption. The label is a form control not an ActiveX control.

Hope someone can help.

Regards,

Robert

You can't use Form labels on userforms !
 
Upvote 0
the active label’s (i.e. just clicked) userform caption.

No idea what that means. Is it a label on a userform? If so, do you want the label caption or the form caption? If not, what have userforms got to do with it?
 
Upvote 0
Hi there,

Thanks for the replies.

I have tried Application.Caller but this isn't for a label (as far as I can teel anyways).

If so, do you want the label caption

Yes!! I just want the caption (it's name here as I don't change it after it's been set) of the label I have clicked.

Thanks again,

Robert
 
Upvote 0
On a userform or worksheet? If userform, use its click event; if sheet, application.caller is correct if this is in a macro assigned to the label.
 
Upvote 0
Hi Rory,

It's a userform. Perhaps the following will show what I'm trying to do:

Code:
Private Sub lbl04_Click()
   
   Dim strMyName As String
   
   strMyname = 'How would I return "lbl04" to the 'strMyName' variable?
   
End Sub

Kind regards,

Robert
 
Upvote 0
You'd need to type it in (activecontrol won't work for labels).
 
Upvote 0
OK then. I had this but thought (was hoping) the control would be intuitive (perhaps by grabbing the caption somehow).

Thanks for the responses / help :)
 
Upvote 0
Can I ask why you need it, given that you have to put the code in the click event anyway?
 
Upvote 0

Forum statistics

Threads
1,224,599
Messages
6,179,828
Members
452,946
Latest member
JoseDavid

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top