PC Review


Reply
Thread Tools Rate Thread

Call UserForm procedures from another workbook

 
 
Mats Samson
Guest
Posts: n/a
 
      2nd Mar 2008
Is it possible to Run a Userform.Show and call/run a procedure in the
Userform from another active workbook once the form is loaded but hidden.
I'm switching from the Userform to the "data" workbook, selects the data to
copy and press a button to copy & paste, switching back to the Userform and
continues to manipulate the data. I can do it with starting a procedure in a
module in the same workbook as the userform but I'd like to jump directly
back to the Userform.
 
Reply With Quote
 
 
 
 
Bob Phillips
Guest
Posts: n/a
 
      2nd Mar 2008
You cannot access a class in another workbook, and a userform is just a
special type of class, add-in or not, directly. You have to get at it in a
roundabout way.

In the workbook with the userform create a standard code module procedure
for creating a form object and loading the form

Dim theForm As UserForm1

Sub LoadForm()
Set theForm = New UserForm1
End Sub

and another procedure to call into the form to invoke one of its methods
(make sure that the method is decalred as Public)

Sub CallIntoForm()
theForm.cmdButton_Click
End Sub


Then in the calling workbook, you invoke that routine like so


Application.Run "'The Userform Workbook.xls'!LoadForm"
Application.Run "'The Userform Workbook.xls'!CallIntoForm"


--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"Mats Samson" <(E-Mail Removed)> wrote in message
news:39B9D781-3816-4497-9D9C-(E-Mail Removed)...
> Is it possible to Run a Userform.Show and call/run a procedure in the
> Userform from another active workbook once the form is loaded but hidden.
> I'm switching from the Userform to the "data" workbook, selects the data
> to
> copy and press a button to copy & paste, switching back to the Userform
> and
> continues to manipulate the data. I can do it with starting a procedure in
> a
> module in the same workbook as the userform but I'd like to jump directly
> back to the Userform.



 
Reply With Quote
 
Mats Samson
Guest
Posts: n/a
 
      2nd Mar 2008
I get compile errors. Dim…UserForm1 errors to “User-defined type not defined”
but I guess the 1 is the problem. But removing it I get “Invalid use of New
keyword” in the Loadform procedure instead!
Please observe that the UserForm is already loaded but hidden when working
in the other workbook. Excel seems to have a problem pasting data to cells
linked to the UserForm (textboxes), very often it starts calculating
endlessly. (Ctrl-Alt-Del is the only way out). I had an idea to reduce the
workload after the paste operation by reducing the number of steps getting
back and show the UserForm again.
Regards
Mats

"Bob Phillips" wrote:

> You cannot access a class in another workbook, and a userform is just a
> special type of class, add-in or not, directly. You have to get at it in a
> roundabout way.
>
> In the workbook with the userform create a standard code module procedure
> for creating a form object and loading the form
>
> Dim theForm As UserForm1
>
> Sub LoadForm()
> Set theForm = New UserForm1
> End Sub
>
> and another procedure to call into the form to invoke one of its methods
> (make sure that the method is decalred as Public)
>
> Sub CallIntoForm()
> theForm.cmdButton_Click
> End Sub
>
>
> Then in the calling workbook, you invoke that routine like so
>
>
> Application.Run "'The Userform Workbook.xls'!LoadForm"
> Application.Run "'The Userform Workbook.xls'!CallIntoForm"
>
>
> --
> HTH
>
> Bob
>
> (there's no email, no snail mail, but somewhere should be gmail in my addy)
>
> "Mats Samson" <(E-Mail Removed)> wrote in message
> news:39B9D781-3816-4497-9D9C-(E-Mail Removed)...
> > Is it possible to Run a Userform.Show and call/run a procedure in the
> > Userform from another active workbook once the form is loaded but hidden.
> > I'm switching from the Userform to the "data" workbook, selects the data
> > to
> > copy and press a button to copy & paste, switching back to the Userform
> > and
> > continues to manipulate the data. I can do it with starting a procedure in
> > a
> > module in the same workbook as the userform but I'd like to jump directly
> > back to the Userform.

>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Call VB procedures from Access GeorgeMar Microsoft Access VBA Modules 6 25th Jul 2004 01:18 AM
Passing ARGUMENTS between event procedures of a USERFORM jason Microsoft Excel Programming 8 10th Nov 2003 07:36 PM
! Call Procedures in Word ! Wembly Microsoft Access VBA Modules 1 3rd Nov 2003 02:31 PM
cannot call procedures from immediate window Matt Microsoft Access 0 23rd Sep 2003 03:43 PM
Remote Procedures Call Faye Ferrell Windows XP General 4 12th Aug 2003 04:48 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:10 PM.