ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   What does the Userform.Tag do? (https://www.excelbanter.com/excel-programming/440274-what-does-userform-tag-do.html)

Brad E.

What does the Userform.Tag do?
 
I am curious what the Tag part of a Userform is for?
--
Thanks, Brad E.

Andy Pope

What does the Userform.Tag do?
 
Hi,

The help files says,

Stores additional information about an object.

Syntax

object.Tag [= String]

The Tag property syntax has these parts:

Part Description
object Required. A valid object.
String Optional. A string expression identifying the object. The default
is a zero-length string ("").


Remarks

Use the Tag property to assign an identification string to an object
without affecting other property settings or attributes.

For example, you can use Tag to check the identity of a form or control
that is passed as a variable to a procedure.

Cheers
Andy

On 05/03/2010 12:51, Brad E. wrote:
I am curious what the Tag part of a Userform is for?


--

Andy Pope, Microsoft MVP - Excel
http://www.andypope.info


Ryan H

What does the Userform.Tag do?
 
The Tag property is String that can be used for anything you wish to help
identify any control. Most controls have them. To me it's kinda used as a
built in custom univerisal property.

In your case for example, lets say you have 3 userforms. Userfrom1 and
Userform2 have the Tag property set to "Run Code". Userform3 has nothing as
a Tag. Now lets say you want to run a procedure for all userforms with Tag =
"Run Code". You would put this in the Initialize Event of each userform.

Private Sub UserForm_Initialize()
If Me.Tag = "Run Code" Then Call MySub
End Sub

Hope this helps! If so, let me know, click "YES" below.
--
Cheers,
Ryan


"Brad E." wrote:

I am curious what the Tag part of a Userform is for?
--
Thanks, Brad E.


Dave Peterson

What does the Userform.Tag do?
 
I've seen some code where it's used as (essentially) a variable to pass
information back to the routine that loaded and showed the userform.

For instance, I created a userform with two commandbuttons and a single
checkbox.

This was the code behind the userform:

Option Explicit
Private Sub CommandButton1_Click()
Me.Tag = "cancel"
Me.Hide
End Sub
Private Sub CommandButton2_Click()
Me.Tag = "ok"
Me.Hide
End Sub
Private Sub UserForm_Initialize()
Me.CommandButton1.Caption = "Cancel"
Me.CommandButton2.Caption = "ok"
End Sub

Then I loaded the userform (and read the results) in this code in a General
module:

Option Explicit
Sub testme()

Dim UF1 As UserForm1

'load the userform
Set UF1 = New UserForm1

UF1.Show

If UF1.Tag = "ok" Then
MsgBox UF1.CheckBox1.Value
Else
MsgBox "User hit cancel, don't trust the checkbox!"
End If

Unload UF1

End Sub

But you could use it to pass any other info to the userform, too--maybe a string
that initializes a textbox????


Brad E. wrote:

I am curious what the Tag part of a Userform is for?
--
Thanks, Brad E.


--

Dave Peterson


All times are GMT +1. The time now is 10:16 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com