userform and variable

G

Gary Keramidas

anyway to set a userform name to a variable i can use with <variable name>
instead of with userform1, with userform2, etc?
 
G

Guest

Don't think so, what are you trying to accomplish? Actually i'm not even sure
of the question, are you just wanting to change the name of the userform? or
set the name to a variable?
 
B

Bob Phillips

Is this the sort of thing you had in mind


Dim oUserForm As Object
On Error GoTo err
Set oUserForm = UserForms.Add("Userform1")
'...

With oUserform
.Show


--
---
HTH

Bob

(change the xxxx to gmail if mailing direct)
 
J

John Coleman

Hi Bob,

What is UserForms? I can't find it in the documentation. From your code
fragment it looks like a collection - but I created a spreadsheet with
2 userforms and when I type "?UserForms.Count" in the immediate window
I get 0 rather than 2. Is there any way to do something like the
following code fragment wants to do:

UserForms(myForm).Show

where myForm is a string variable? I know that you can do this sort of
thing for embedded active X controls via the Shapes collection.

Just curious - I can't imagine where I would need it in my code.

-John Coleman
 
S

Susan

gary - i'd be interested in the answer to this, too, because when i
change the name of a userform to something like frmGenerate, i can't
get the initialization to run..........
but i didn't think of declaring it as a variable in my global
declarations module.........
susan
 
G

Gary Keramidas

bob:

i was looking to use a variable to create the userform name. so instead of with
userform1, with userform2, i could use:
with userform(i)
..
..
end with
or
uform = userform1
then use the variable to manipulate the form ( i know this won't work, but)
with uform
..
..
end with

i've used me.controls("textbox" & i) and am wondering if there is a way to do
this with the form itself.

Gary
 
G

Gary Keramidas

thanks for the link, tom. looks like this is what i wanted

uform = "Userform1"
With VBA.UserForms.Add(uForm)
.Show
.Top = 100
End With
 
G

Gary Keramidas

here's the problem I've run into using VBA.UserForms.Add(uForm).

i set uform = "UF2"
then
VBA.UserForms.Add(uForm).show

unload uf2 doesn't work. the form is still displayed.
 
B

Bob Phillips

You unload it from within the form, not the other code.

--
---
HTH

Bob

(change the xxxx to gmail if mailing direct)
 
T

Tom Ogilvy

If you have

Private Sub frmGenerate_Initialize()

then that is the problem. No matter the userform name, it should always be

Private Sub Userform_Initialize()


--
Regards,
Tom Ogilvy


Susan said:
gary - i'd be interested in the answer to this, too, because when i
change the name of a userform to something like frmGenerate, i can't
get the initialization to run..........
but i didn't think of declaring it as a variable in my global
declarations module.........
susan
 
S

Susan

tom - yes, that's what i have to do. but if you have a macro where
you're calling various userforms from the main macro, it would be nice
to be able to differentiate them more easily, even tho i know the
initialize sub is directly connected to that specific userform......
when i've got five different userform windows open it gets a little
confusing LOL
susan

Tom said:
If you have

Private Sub frmGenerate_Initialize()

then that is the problem. No matter the userform name, it should always be

Private Sub Userform_Initialize()
 
B

Bob Phillips

then you seem to be asking the same question as Gary, so the answer is the
same

--
---
HTH

Bob

(change the xxxx to gmail if mailing direct)
 

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