Don't understand the purpose of the "Tag" property

Glory

Well-known Member
Joined
Mar 16, 2011
Messages
640
Why wouldn't you just look at the object's name, since every object has to have a unique name anyway?
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
A tag value can be changed at runtime, and can hold any text you like. Some creative uses have been found ...
 
Upvote 0
I'm looking at code that links a button created on a userform at runtime with some code in a class module.

I don't understand the use of the tag property here. is it just so that if the user wants to they can extract the identity of a certain button?

Wouldn't "control.name & i" have worked for that?

Code:
  For Each obj In Me.Controls
        If TypeName(obj) = "CommandButton" Then 
            If Left(obj.Name, 3) = "dyn" Then
            i = i + 1
            ReDim Preserve c(i) 
            Set c(i) = New Class1
            c(i).SetCommandButton obj
            obj.Tag = i
          End If
        End If
    Next
End Sub
 
Upvote 0
Creating controls at runtime is not my forte. It may simply be a matter of taste. I guess it depends on how the tag value is used (if at all) later on - perhaps it's a convenience. Sometimes you just do what you're used to doing, even if other (better) ways exist.
 
Upvote 0

Forum statistics

Threads
1,215,030
Messages
6,122,762
Members
449,095
Latest member
m_smith_solihull

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