Get control of a Userform by the Name

J

joel

If you are talking about a VBA user from in VBA window press F4 (Vie
properties window) and click on the control. The name will be in th
Name property.

If you have a worksheet user form you should be able to click on th
object and the name will be in the box next to the formula box (fx)
 
J

Joe

R

Rick Rothstein

Your description is somewhat confusing... can you give more detail about
what you are actually trying to do?
 
C

Chip Pearson

I want to change the text of a form.

What do you mean by the "text of a form"? I will assume you mean the
Caption that appears on the title bar of the form.

Try some code like the following:

Sub ChangeCaption()
Dim FormName As String
Dim NewCaption As String
Dim UF As UserForm
Dim N As Long
Dim B As Boolean
FormName = "UserForm2"
NewCaption = "This Is New"
Load UserForm1

VBA.UserForms.Add FormName

For N = 0 To VBA.UserForms.Count - 1
If StrComp(VBA.UserForms(N).Name, FormName, _
vbTextCompare) = 0 Then
VBA.UserForms(N).Caption = NewCaption
B = True
Exit For
End If
Next N
If B = True Then
VBA.UserForms(N).Show
End If
End Sub


The form whose caption you want to change must already be loaded into
memory, but not necessarily visible. To load a form into memory
without making it visible, use either of

Load UserForm2

' OR

VBA.UserForms.Add "UserForm2"


Cordially,
Chip Pearson
Microsoft Most Valuable Professional,
Excel, 1998 - 2010
Pearson Software Consulting, LLC
www.cpearson.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top