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?
 

Some videos you may like

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.

xenou

MrExcel MVP
Joined
Mar 2, 2007
Messages
16,695
Office Version
  1. 2013
Platform
  1. Windows
A tag value can be changed at runtime, and can hold any text you like. Some creative uses have been found ...
 

Glory

Well-known Member
Joined
Mar 16, 2011
Messages
640
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
 

xenou

MrExcel MVP
Joined
Mar 2, 2007
Messages
16,695
Office Version
  1. 2013
Platform
  1. Windows
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.
 

Watch MrExcel Video

Forum statistics

Threads
1,109,465
Messages
5,528,962
Members
409,848
Latest member
Blomsten
Top