PC Review


Reply
Thread Tools Rate Thread

Call to Sub Routine which exists in seperate workbook

 
 
Coby
Guest
Posts: n/a
 
      25th Jan 2008
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.

 
Reply With Quote
 
 
 
 
Bill Martin
Guest
Posts: n/a
 
      25th Jan 2008
Well, the simple way is to open the codeless workbook's VBA module and click
on "Tools/References" at the top. Then select the name of the book with the
code and check it's box. At that point everything in the second book is
available to the first. However it will also automatically open the second
book whenever you open the first if that's a problem.

Once you've checked the box as above, then you just use the subroutine name
in the first book same as if the routine lived in the first book.

Bill
-------------------------
"Coby" <(E-Mail Removed)> wrote in message
news:c9628d4e-367b-41ca-9b2d-(E-Mail Removed)...
> 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.
>



 
Reply With Quote
 
Coby
Guest
Posts: n/a
 
      25th Jan 2008
On Jan 25, 1:10*pm, "Bill Martin" <martin_spamt...@verizon.net> wrote:
> Well, the simple way is to open the codeless workbook's VBA module and click
> on "Tools/References" at the top. *Then select the name of the book withthe
> code and check it's box. *At that point everything in the second book is
> available to the first. *However it will also automatically open the second
> book whenever you open the first if that's a problem.
>
> Once you've checked the box as above, then you just use the subroutine name
> in the first book same as if the routine lived in the first book.
>
> Bill
> -------------------------"Coby" <coby.giff...@selectbuild.com> wrote in message
>
> news:c9628d4e-367b-41ca-9b2d-(E-Mail Removed)...
>
>
>
> > 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.- Hide quoted text -

>
> - Show quoted text -


Having both workbooks open is not really a problem in the case of my
situation.
I would like to make the call to the sub routine completely via code,
however.

With both workbooks open I kept trying to do Call XYZ_SubRoutine, but
since the module exists in the other workbook I get the compile
error. Perhaps, there is a different way to initiate a sub routine?

Or, I may be able to somehow use the method you suggested, but through
code instead of the user?

Thanks for your input . . . I may have a new approach to try.
 
Reply With Quote
 
Tim Zych
Guest
Posts: n/a
 
      25th Jan 2008
I think one way is to link a forms button or shape in the codeless to a
macro in the code workbook (e.g. Assign Macro). If the code workbook is
closed, Excel will automatically open it once the linked object is clicked.

I'm not a fan of linking, however. When I need to make a workbok with as
light a macro footprint as possible, prefer to add a couple of macros whose
sole responsibility is to call macros in the code workbook using
Application.Run.

--
Tim Zych
SF, CA

"Coby" <(E-Mail Removed)> wrote in message
news:c9628d4e-367b-41ca-9b2d-(E-Mail Removed)...
> 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.
>



 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      25th Jan 2008
Another way is to open the other workbook and call the macro using
application.run (instead of the reference):

Dim OtherWkbk as workbook
set otherwkbk = nothing
on error resume next
set otherwkbk = workbooks("somename.xls") '<-- no drive, no path
on error goto 0

if otherwkbk is nothing then
'it's not open, so open it
set otherwkbk = workbooks.open("C:\folderhere\somenamehere.xls")
end if

application.run "'" & otherwkbk.name & "'!somemacronamehere"



Coby wrote:
>
> 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.


--

Dave Peterson
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Routine for checking if file exists Centurion Microsoft Excel Programming 6 26th Jan 2005 11:02 PM
Call routine on subform =?Utf-8?B?c21rMjM=?= Microsoft Access VBA Modules 1 22nd Jan 2005 10:15 PM
How to call a VBA routine in an add-in from a VB app? Camden Microsoft Excel Programming 1 1st Nov 2004 05:17 PM
Please help - How to call functions that exists in the main application. The call should be initiated from one of the components. Anand Ganesh Microsoft C# .NET 5 16th Oct 2004 01:53 AM
Re: Please help - How to call functions that exists in the main application. The call should be initiated from one of the components. Baavgai Microsoft C# .NET 0 4th Sep 2004 05:54 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:09 PM.