ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Calling Form Routine from Another Workbook (https://www.excelbanter.com/excel-programming/419299-calling-form-routine-another-workbook.html)

Denis[_4_]

Calling Form Routine from Another Workbook
 
You can call a routine in another workbook by doing:
Application.Run "SomeBook.xls!SomeRoutine"

Since you can call a routine in a form by:
Call SomForm.FormRoutine

I was hoping that you could call a form routine from another workbook
by doing:
Application.Run "SomeBook.xls!SomeForm.FormRoutine"
but this doesn't work.

Is there a way to do this?

On a related note, is there a way to unload a form from another
workbook. My understanding is that calling a routine in a form will
automatically load it (if it isn't already loaded) but there are times
when you would want to unload a form to guarantee you are starting
fresh.

Denis

Peter T

Calling Form Routine from Another Workbook
 
1.
Application.Run "SomeBook.xls!SomeForm.SomeRoutine"

Put code in SomeRoutine to run (ie load and show) the form (in same project
as SomeRoutine)

2.
Yes you are right, as soon as you reference a userform it will load into
memory and stay there until explicitly unloaded (or the wb is closed)

To unload one or all forms in a project -

Dim i as long

For i = 1 to Userforms.count To 1 Step -1
' If Userforms(i - 1).name = "myFormName" Then '' only unload this form
Unload Userforms(i - 1)
' End If
Next

uncomment "If..." & "End If" to only unload a particular form, if loaded


Regards,
Peter T


"Denis" wrote in message
...
You can call a routine in another workbook by doing:
Application.Run "SomeBook.xls!SomeRoutine"

Since you can call a routine in a form by:
Call SomForm.FormRoutine

I was hoping that you could call a form routine from another workbook
by doing:
Application.Run "SomeBook.xls!SomeForm.FormRoutine"
but this doesn't work.

Is there a way to do this?

On a related note, is there a way to unload a form from another
workbook. My understanding is that calling a routine in a form will
automatically load it (if it isn't already loaded) but there are times
when you would want to unload a form to guarantee you are starting
fresh.

Denis





All times are GMT +1. The time now is 09:13 AM.

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