Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 10th, 2007, 11:21 AM
Authorized User
 
Join Date: Oct 2006
Posts: 45
Thanks: 0
Thanked 0 Times in 0 Posts
Default How do I call a sub in a different workbook?

What is the method to Start a subroutine in workbook "B" from workbook "A"?

Also, if any public variables or subs in "B" have the same name as public variables in "A", will it cause conflicts? (Because workbook "A" is actually in a routine when it initiates the routine in "B")

Thanks

 
Old April 12th, 2007, 10:34 AM
Friend of Wrox
 
Join Date: Feb 2007
Posts: 163
Thanks: 0
Thanked 2 Times in 2 Posts
Default

For a public sub:
Call Workbooks("TargetBookName").Worksheets("SheetNameW ithFunction").SubName(OptionalPassedVariables)

For a Public Function you want to pass value back from:
sMyVal = Workbooks("TargetBookName").Worksheets("SheetNameW ithFunction").FunctionName(OptionalPassedVariables )

You're declaring public variables? Not only that but ones that are actually duplicated workbook to workbook but have differing values? I'd try to steer clear of declaring any public variables if you can help it.

When declared public a variable is seen throughout the entire application. If you must and they must be the same then try specifying "Option Private Module" in the module.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Call to subroutine from seperate workbook Coby Excel VBA 2 February 1st, 2008 10:15 PM
Workbook Open anup.bihani Excel VBA 2 November 30th, 2006 01:05 AM
Inactive Workbook halem2 Beginning VB 6 0 June 8th, 2006 04:42 PM
Shared workbook. seasider Excel VBA 0 January 20th, 2006 12:02 PM
workbook not found! timoma Access VBA 2 January 17th, 2005 08:47 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.