Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default Call to Sub Routine which exists in 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.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 54
Default Call to Sub Routine which exists in seperate workbook

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" wrote in message
...
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.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default Call to Sub Routine which exists in seperate workbook

On Jan 25, 1:10*pm, "Bill Martin" 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 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" wrote in message

...



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.
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 389
Default Call to Sub Routine which exists in seperate workbook

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" wrote in message
...
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.



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Call to Sub Routine which exists in seperate workbook

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
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
Sub Routine Call From a Macro D. Jones Excel Discussion (Misc queries) 1 November 8th 07 11:01 PM
How to keep a Variable alive after a Call to Sub Routine Dennis Excel Discussion (Misc queries) 2 July 27th 05 10:57 PM
Routine for checking if file exists Centurion Excel Programming 6 January 26th 05 11:02 PM
How to call a VBA routine in an add-in from a VB app? Camden Excel Programming 1 November 1st 04 05:17 PM
Call MS Word envelope printing routine? Richard[_28_] Excel Programming 0 April 27th 04 09:08 PM


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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"