PC Review


Reply
Thread Tools Rating: Thread Rating: 1 votes, 5.00 average.

Call a sub procedure from another workbook

 
 
jbronnum@gmail.com
Guest
Posts: n/a
 
      22nd Nov 2007
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?
 
Reply With Quote
 
 
 
 
=?Utf-8?B?RlN0MQ==?=
Guest
Posts: n/a
 
      22nd Nov 2007
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

"(E-Mail Removed)" 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?
>

 
Reply With Quote
 
jbronnum@gmail.com
Guest
Posts: n/a
 
      22nd Nov 2007
On 22 Nov., 17:29, FSt1 <F...@discussions.microsoft.com> 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
>
>
>
> "jbron...@gmail.com" 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
 
Reply With Quote
 
Chip Pearson
Guest
Posts: n/a
 
      22nd Nov 2007
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)


<(E-Mail Removed)> wrote in message
news:43a0d825-c32e-4184-90c4-(E-Mail Removed)...
>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?


 
Reply With Quote
 
jbronnum@gmail.com
Guest
Posts: n/a
 
      23rd Nov 2007
On 22 Nov., 17:44, "Chip Pearson" <c...@cpearson.com> 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)
>
> <jbron...@gmail.com> wrote in message
>
> news:43a0d825-c32e-4184-90c4-(E-Mail Removed)...
>
>
>
> >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 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
Only Explicit Call of Procedure in another workbook??? =?Utf-8?B?a29oYWk=?= Microsoft Excel Programming 1 15th May 2007 05:51 PM
Call VBA procedure ilocated in another workbook oleg.melentyev@gmail.com Microsoft Excel Programming 1 26th Feb 2007 11:25 PM
Call a procedure in the workbook from a worksheet =?Utf-8?B?U2VsaW5h?= Microsoft Excel Programming 3 21st Apr 2005 01:04 PM
REMOTE CALL PROCEDURE call (RPC) SERVICE Pete Q Windows XP Networking 2 23rd Nov 2003 03:34 PM
remote call procedure call failed Dave Warwick Windows XP Networking 0 5th Jul 2003 04:59 AM


Features
 

Advertising
 

Newsgroups
 


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