View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 6,953
Default Is there an alternative to Application.Run

You would need to create a reference from the calling workbook to the
workbook with the procedure. Do this in the VBE under tools=References.
Make sure you have given the called workbook a unique project name in
properties (rather than the default VBProject).

Note that whenever you open the referencing workbook, the referenced
workbook will be opened as well. You can not close the referenced workbook
until the referencing workbook is closed.

Once the reference is established, you can call routines in the referenced
workbook as if they were local. You wouldn't need to qualify with the
workbook name or module names unless their were duplicate names in scope.

--
Regards,
Tom Ogilvy


"John Pritchard" wrote:

I'd like to call sub routines that reside in another workbook. I know about
application.run but if I want to pass arguments byref it doesn't seem to work
(i.e. the changed value is not passed back). In the Vb help on calling
procedures with the same name there's this example:-
Sub Main()
[MyProject.vbp].[MyModule].Main
End Sub

I've tried renaming projects and using this:-
Sub Main()
[MyProject.xls].[MyModule].Hello
End Sub

..but can't make it see my hello procedure.
Where am I going wrong and once right will it allow me to do things like
this:-

Sub Main()
a = 1
b = 2
[MyProject.xls].[MyModule].Swap(a,b)
msgbox ("Swapped " & a & "," & b)
End Sub

Any help much appreciated! J.P.