Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
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.











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
Calling VBA add-in functions/subs from another Excel file. Bret Holle Excel Programming 1 September 17th 04 01:43 AM
Calling workbooks with apostrophes in name? Don Wiss Excel Programming 4 July 19th 04 01:11 PM
calling subs Mike Excel Programming 4 April 8th 04 08:22 PM
calling subs, Doesn't seem to run fisrt time? CAA[_21_] Excel Programming 2 April 1st 04 08:23 PM
calling private subs dunlklee Excel Programming 1 December 16th 03 08:40 AM


All times are GMT +1. The time now is 06:56 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"