Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Call a sub procedure from another workbook

I have a number of different workbooks all using the same sub
procedure. I want to put this sub procedure in just one workbook and
call this sub procedure from a number of other workbooks

How can i call a sub procedure from another workbook?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,942
Default Call a sub procedure from another workbook

hi
the best way i know to do that is to save the file your macro is in to the
xlstart folder as Personal.xls and hide the file. on my pc the xlstart folder
is at
C:\Program files\microsoft office\office 10\xlstart\
your personal.xls file will open in the background when xl starts and all
macros in the personal.xls file will be available to run on any file.
I have a number of macros in my personal xls and run many from a custom menu
or custom icon.

Regards
FSt1

" wrote:

I have a number of different workbooks all using the same sub
procedure. I want to put this sub procedure in just one workbook and
call this sub procedure from a number of other workbooks

How can i call a sub procedure from another workbook?

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Call a sub procedure from another workbook

On 22 Nov., 17:29, FSt1 wrote:
hi
the best way i know to do that is to save the file your macro is in to the
xlstart folder as Personal.xls and hide the file. on my pc the xlstart folder
is at
C:\Program files\microsoft office\office 10\xlstart\
your personal.xls file will open in the background when xl starts and all
macros in the personal.xls file will be available to run on any file.
I have a number of macros in my personal xls and run many from a custom menu
or custom icon.

Regards
FSt1



" wrote:
I have a number of different workbooks all using the same sub
procedure. I want to put this sub procedure in just one workbook and
call this sub procedure from a number of other workbooks


How can i call a sub procedure from another workbook?- Skjul tekst i anførselstegn -


- Vis tekst i anførselstegn -


Hi FSt1

Thank you for your answer.

Does this also work when there are multiple users of the workbook?

What commando should i use to call the procedure? Call "procedure
name"?

Johan
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Call a sub procedure from another workbook

There are basically three ways you can go about this. The first is to have
both the workbook that contains the sub and the workbook that needs to use
the sub open and use Application.Run to execute the code. E.g.,

Application.Run "'WorkbookWithSub.xls'!TheSubName"

Pay attention to the apostrophes. They are not necessary if your workbook
name does not contain spaces, but are necessary if the workbook name
contains spaces. In either case, they are harmless.

The second method is to create a reference from the workbook that needs to
use the sub to the workbook that contains the sub. In the workbook that
contains the sub, go to the Tools menu in VBA and choose "VBA Project
Properties". Change the name of the project to something meaningful, e.g.,
MyProject. Then open the workbook that needs to use the sub, go to to the
Tools menu in VBA, choose References, and select and check "MyProject" or
whatever you named the project. With this reference in place, you can call
the sub as if it resided in the same workbook. If there is the possibility
of a name collision (two subs with the same name), you can prefix the sub
name with the library name:

MyProject.MySub

Finally, you could put the sub into an Add-In and load that add-in via the
Add-Ins dialog on the Tools menu in Excel. With the add-in loaded, you can
call the sub directly as if it existed in the same workbook. Again, you can
avoid name collisions by including the project name of the add-in.

MyAddInProject.MySub


--
Cordially,
Chip Pearson
Microsoft MVP - Excel, 10 Years
Pearson Software Consulting
www.cpearson.com
(email on the web site)


wrote in message
...
I have a number of different workbooks all using the same sub
procedure. I want to put this sub procedure in just one workbook and
call this sub procedure from a number of other workbooks

How can i call a sub procedure from another workbook?


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Call a sub procedure from another workbook

On 22 Nov., 17:44, "Chip Pearson" wrote:
There are basically three ways you can go about this. The first is to have
both the workbook that contains the sub and the workbook that needs to use
the sub open and use Application.Run to execute the code. E.g.,

Application.Run "'WorkbookWithSub.xls'!TheSubName"

Pay attention to the apostrophes. They are not necessary if your workbook
name does not contain spaces, but are necessary if the workbook name
contains spaces. In either case, they are harmless.

The second method is to create a reference from the workbook that needs to
use the sub to the workbook that contains the sub. In the workbook that
contains the sub, go to the Tools menu in VBA and choose "VBA Project
Properties". Change the name of the project to something meaningful, e.g.,
MyProject. Then open the workbook that needs to use the sub, go to to the
Tools menu in VBA, choose References, and select and check "MyProject" or
whatever you named the project. With this reference in place, you can call
the sub as if it resided in the same workbook. If there is the possibility
of a name collision (two subs with the same name), you can prefix the sub
name with the library name:

MyProject.MySub

Finally, you could put the sub into an Add-In and load that add-in via the
Add-Ins dialog on the Tools menu in Excel. With the add-in loaded, you can
call the sub directly as if it existed in the same workbook. Again, you can
avoid name collisions by including the project name of the add-in.

MyAddInProject.MySub

--
Cordially,
Chip Pearson
Microsoft MVP - Excel, 10 Years
Pearson Software Consultingwww.cpearson.com
(email on the web site)

wrote in message

...



I have a number of different workbooks all using the same sub
procedure. I want to put this sub procedure in just one workbook and
call this sub procedure from a number of other workbooks


How can i call a sub procedure from another workbook?- Skjul tekst i anførselstegn -


- Vis tekst i anførselstegn -


Hi Chip

Thank you veruy much

I will try it out

Best regards

Johan


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
Only Explicit Call of Procedure in another workbook??? kohai Excel Programming 1 May 15th 07 05:51 PM
Call VBA procedure ilocated in another workbook [email protected] Excel Programming 1 February 26th 07 11:25 PM
procedure call BorisS Excel Programming 1 September 18th 06 07:16 AM
Call a procedure in the workbook from a worksheet Selina Excel Programming 3 April 21st 05 01:04 PM
procedure won't call John Gittins Excel Programming 0 August 5th 03 08:17 PM


All times are GMT +1. The time now is 02:25 AM.

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"