View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
R.VENKATARAMAN R.VENKATARAMAN is offline
external usenet poster
 
Posts: 74
Default Calling subs from different workbooks

I have a workbook called book1.xls in a folder(folder <my documents. it has
a sub "rv"
I have another workbook called Book2.xls in another folder and a
sub ------calling for sub rv

code in book1

Public Sub rv()
ActiveSheet.Range("a1") = 1234567
End Sub

code in book2

Public Sub rrone ()
Call rv

End Sub

Even before running this sub <rrone , when both the workbooks are open I go
to the VBeditor click the vbproject book2 and in tools-reference I see the
vbproject <book1 and If I tick this and click Ok I get error message

"name conflicts with exiting module, project or object library"

so I did not tick it . nor did I run sub <rrone. WHERE DID I DO THE
MISTAKE?

on the other hand even if I close book1

and run another sub OF book2 given below
WITHOUT REFERNCING BOOK1 IN VBEDITOR OF BOOK2

(this code is in Book2)

Public Sub rr()
Application.Run "'e:\temporary\book1.xls'!rv"
End Sub

book1 automatically opens and the sub "rv" of Book1 is operated
successfully. I have not referenced book1 in book2.-I havae not checked
the reference.

As this is only an experiment I used trivial subs. apologise;.







Tom Ogilvy wrote in message
news:OdHCXLMTBHA.1392@tkmsftngp07...
Just to add, if you set a reference to the other workbook, whenever the
workbook with the reference is opened, excel will open the referenced
workbook.

Regards,
Tom Ogilvy

"Norman Harker" wrote in message
...
Hi Steven!

You have choices:

You can establish a reference to the other workbook. First, open both
workbooks and in the one that calls the sub, in the VBE use Tools
References and check the name of the workbook containing the sub.

Thereafter
you can call the sub by name whether or not the workbook with it in is

open
using
MySub
Call MySub

Another method is to use the Run method:

Application.Run "'My Macro Book.xls'!MySub"

hth

"Steven Taylor" wrote in message
news:4e6301c14cb1$f2bd5020$3def2ecf@TKMSFTNGXA14.. .
How do I call a sub in one workbook, from code in another
workbook?
Thanking you in anticipation.