Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Can't call a sub in a UserForm using Application.Run

25 views
Skip to first unread message

Mike

unread,
Feb 20, 2010, 9:36:31 PM2/20/10
to
I'm having problems calling Public Sub XXX that is in Userform1.

Tried

Application.Run "Userform1.XXX"

but will not work. Works OK if XXX is in a Standard Module,

Thanks for any help.


joel

unread,
Feb 21, 2010, 3:03:23 AM2/21/10
to

Is the userform loaded? You aren't suppose to call user form routine
dirrectly. If yo have common code move the macro from the userform to a
module and then call the routine.. You can call the common code from a
userform, right!


--
joel
------------------------------------------------------------------------
joel's Profile: 229
View this thread: http://www.thecodecage.com/forumz/showthread.php?t=181173

[url="http://www.thecodecage.com"]Microsoft Office Help[/url]

Dave Peterson

unread,
Feb 21, 2010, 8:21:24 AM2/21/10
to
Try:
Call userform1.xxx

(with userform1 loaded/shown)

--

Dave Peterson

Dave Peterson

unread,
Feb 21, 2010, 9:04:49 AM2/21/10
to
It doesn't matter if it's loaded or not.

--

Dave Peterson

Mike

unread,
Feb 21, 2010, 9:20:55 AM2/21/10
to
It appears that Application.Run can be in a Standard Module, a Class Module
or a Userform module and it cannot call a sub in a Userform Module. Thanks.
"joel" <joel....@thecodecage.com> wrote in message
news:joel....@thecodecage.com...

Mike

unread,
Feb 21, 2010, 9:29:05 AM2/21/10
to
The reason I have to use Application run is because I need the XXX to be a
variable, like

dim zzz as string

zzz= "Userform1.xxx"

Application.Run zzz

The Call userform1.xxx does work but "Call" can't take a variable.

Thanks Peter

"Dave Peterson" <pete...@verizonXSPAM.net> wrote in message
news:4B813354...@verizonXSPAM.net...

Chip Pearson

unread,
Feb 21, 2010, 9:46:42 AM2/21/10
to
>The Call userform1.xxx does work but "Call" can't take a variable.

Use CallByName. E.g., in a regular code module


Sub AAA()
Dim FF As UserForm1
Dim S As String
S = "HelloWorld"
Set FF = New UserForm1
CallByName FF, S, VbMethod
End Sub

Here, HelloWorld is a method defined in UserForm1's code module. You
need to create an instance of UserForm1 but you need not Show the form
to make it visible.

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


On Sun, 21 Feb 2010 06:29:05 -0800, "Mike" <mike...@hotmail.com>
wrote:

Mike

unread,
Feb 21, 2010, 10:40:09 AM2/21/10
to
Thanks Chip. That's exactly what I need. Works great!!


"Chip Pearson" <ch...@cpearson.com> wrote in message
news:hnh2o5hvoii9hphs5...@4ax.com...

0 new messages