Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default using forms and modules in multiple workbooks

I want a VBA code to use in WorkBook A that will look in
another open workbook, WorkBook B and use that WorkBook's
Forms and modules???
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default using forms and modules in multiple workbooks

First, in workbook B in VBA, go to the Tools menu, choose VBA Project
Properties, and give the project a unique name like ProjB. Then open
workbook A in VBA and go to the Tools menu, choose References, and select
ProjB from the list. Workbook A now references workbook B.

Now, you can call normal subs and functions in B from A as if they were part
of A. To avoid naming conflicts, and for good coding practice, you should
prefix the name of the procedure with the library name. E.g., in A,
ProjB.MacroName

For forms, it is a bit more difficult because forms can directly be called.
They are private to the workbook that contains them. If all you need to do
is show the form, but not access any of its controls, create a macro in B
like the following:

Public Sub ShowTheForm()
UserForm1.Show
End Sub

Then, call this macro from A with code like
ProjB.ShowTheForm

If you need full access to the form and its controls, you need a macro in B
that returns an instance of the form. For example, in B, use code like

Public Function GetForm1() As UserForm1
Set GetForm1 = UserForm1
End Function

Then, in A, call this function to get a reference to the form object.

Dim F As Object
Set F = ProjB.GetForm1()
F.Show


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"scrabtree23" wrote in message
...
I want a VBA code to use in WorkBook A that will look in
another open workbook, WorkBook B and use that WorkBook's
Forms and modules???



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Working with the forms in different workbooks... Joe_Germany Excel Worksheet Functions 0 January 17th 08 06:01 AM
Forms and Modules scrabtree23[_2_] Excel Programming 4 November 11th 03 03:57 PM
Modules and Forms II Pedro Excel Programming 1 November 7th 03 11:19 AM
Modules and Forms Pedro Excel Programming 2 November 6th 03 02:02 PM
Need help on How to programatically Import VBA Project Excel Objects, Forms, Modules JMMach Excel Programming 7 October 21st 03 08:46 PM


All times are GMT +1. The time now is 06:14 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"