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 January 25th, 2008, 04:47 PM
Authorized User
 
Join Date: Apr 2007
Posts: 56
Thanks: 0
Thanked 0 Times in 0 Posts
Default Call to subroutine from seperate workbook

If I had one workbook open, but the vba modules were in another workbook which is closed, does anyone know if there is a way for the codeless workbook to run the subroutine which is in the other workbook?

Any help is sincerely appreciated.

Coby.

 
Old January 26th, 2008, 03:20 AM
Friend of Wrox
 
Join Date: Sep 2005
Posts: 812
Thanks: 1
Thanked 53 Times in 49 Posts
Default

You can use the application.Run and do the needful. However, you need to open the workbook containing the macros to execute it

Here is the code:

Code:
Sub Run_Antoher_Macro()

Dim AnotherWrkBook As String
Dim MacroInAnotherWbk As String
Dim oWB As Workbook


AnotherWrkBook = "MyMacro.XLS"
MacroInAnotherWbk = "Copy_Data"
Set oWB = Workbooks.Open("c:\" & AnotherWrkBook)


Application.Run "'" & AnotherWrkBook & "'!" & MacroInAnotherWbk

oWB.Close False
End Sub
Cheers
Shasur

http://www.dotnetdud.blogspot.com

VBA Tips & Tricks (http://www.vbadud.blogspot.com)
 
Old February 1st, 2008, 10:15 PM
Authorized User
 
Join Date: Apr 2007
Posts: 56
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Good! Thanks a lot . . . I think I was close but did not know all of the Syntax such as the ' and the ! and where they needed to be.

That did it.

Have a nice weekend and thanks again.
Coby.






Similar Threads
Thread Thread Starter Forum Replies Last Post
seperate string by ^ bbvic XSLT 7 July 25th, 2007 02:00 AM
How do I call a sub in a different workbook? TomW Excel VBA 1 April 12th, 2007 10:34 AM
passing parameter to a perl subroutine crmpicco Perl 2 February 16th, 2007 08:07 AM
Seperate Code JsonTerre1 BOOK: ASP.NET Website Programming Problem-Design-Solution 1 November 7th, 2004 04:38 PM
calling subroutine from different module? Raif Access 2 June 15th, 2004 11:56 PM





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