PC Review


Reply
Thread Tools Rate Thread

Call Macro from PERSONAL.XLS

 
 
jutlaux
Guest
Posts: n/a
 
      18th May 2009
I have a macro that is stored in my personal.xls that I would like to be able
to call from another workbook. I have the macro stored in a standard code
module and have it defined as a public type, but when i go to call it from
another workbook I get:

"Compile error:

Sub or Function not defined"

Aside from coping the entire script into the new workbook is there a way to
call a script stored in personal.xls from another workbook?

Thanks!
 
Reply With Quote
 
 
 
 
Dave Peterson
Guest
Posts: n/a
 
      18th May 2009
Dim pWkbk as workbook
set pwkbk = workbooks("Personal.xls")
application.run "'" & pwkb.name & "'!macronamehere", "parm1", "parm2"

or if you're returning a value from a function:

dim res as string 'or variant or long or ...
res = application.run("'" & pwkb.name & "'!macronamehere", "parm1", "parm2")

You could also create a reference to this personal.xls workbook and call it just
like it was built into excel.

Tools|references
(but give the personal.xls's project a nice unique name (not VBAProject).

ps.

If you're using a function living in personal.xls inside a cell:
=personal.xls!functionnamehere(a1,b1,c1)

or save the file as an addin (*.xla) and use it in the cell like it's built into
excel:
=functionnamehere(a1,b1,c1)





jutlaux wrote:
>
> I have a macro that is stored in my personal.xls that I would like to be able
> to call from another workbook. I have the macro stored in a standard code
> module and have it defined as a public type, but when i go to call it from
> another workbook I get:
>
> "Compile error:
>
> Sub or Function not defined"
>
> Aside from coping the entire script into the new workbook is there a way to
> call a script stored in personal.xls from another workbook?
>
> Thanks!


--

Dave Peterson
 
Reply With Quote
 
jutlaux
Guest
Posts: n/a
 
      18th May 2009
I used your application.run suggestion and this did work as needed. Thanks!

I failed to mention that the script being called has a variable that returns
some information. When I use your suggestion the public variable that has
the information to be returned is empty. Thoughts?

Thanks again.

"Dave Peterson" wrote:

> Dim pWkbk as workbook
> set pwkbk = workbooks("Personal.xls")
> application.run "'" & pwkb.name & "'!macronamehere", "parm1", "parm2"
>
> or if you're returning a value from a function:
>
> dim res as string 'or variant or long or ...
> res = application.run("'" & pwkb.name & "'!macronamehere", "parm1", "parm2")
>
> You could also create a reference to this personal.xls workbook and call it just
> like it was built into excel.
>
> Tools|references
> (but give the personal.xls's project a nice unique name (not VBAProject).
>
> ps.
>
> If you're using a function living in personal.xls inside a cell:
> =personal.xls!functionnamehere(a1,b1,c1)
>
> or save the file as an addin (*.xla) and use it in the cell like it's built into
> excel:
> =functionnamehere(a1,b1,c1)
>
>
>
>
>
> jutlaux wrote:
> >
> > I have a macro that is stored in my personal.xls that I would like to be able
> > to call from another workbook. I have the macro stored in a standard code
> > module and have it defined as a public type, but when i go to call it from
> > another workbook I get:
> >
> > "Compile error:
> >
> > Sub or Function not defined"
> >
> > Aside from coping the entire script into the new workbook is there a way to
> > call a script stored in personal.xls from another workbook?
> >
> > Thanks!

>
> --
>
> Dave Peterson
>

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      18th May 2009
The public variable is in personal.xls and you're trying to return that?

If yes, then create a function in personal.xls and call that function:

Function ReturnPublicVar1Val() as string 'variant, long, ...
returnpublicvar1val = MyPublicVariableNameGoesHere
end function



jutlaux wrote:
>
> I used your application.run suggestion and this did work as needed. Thanks!
>
> I failed to mention that the script being called has a variable that returns
> some information. When I use your suggestion the public variable that has
> the information to be returned is empty. Thoughts?
>
> Thanks again.
>
> "Dave Peterson" wrote:
>
> > Dim pWkbk as workbook
> > set pwkbk = workbooks("Personal.xls")
> > application.run "'" & pwkb.name & "'!macronamehere", "parm1", "parm2"
> >
> > or if you're returning a value from a function:
> >
> > dim res as string 'or variant or long or ...
> > res = application.run("'" & pwkb.name & "'!macronamehere", "parm1", "parm2")
> >
> > You could also create a reference to this personal.xls workbook and call it just
> > like it was built into excel.
> >
> > Tools|references
> > (but give the personal.xls's project a nice unique name (not VBAProject).
> >
> > ps.
> >
> > If you're using a function living in personal.xls inside a cell:
> > =personal.xls!functionnamehere(a1,b1,c1)
> >
> > or save the file as an addin (*.xla) and use it in the cell like it's built into
> > excel:
> > =functionnamehere(a1,b1,c1)
> >
> >
> >
> >
> >
> > jutlaux wrote:
> > >
> > > I have a macro that is stored in my personal.xls that I would like to be able
> > > to call from another workbook. I have the macro stored in a standard code
> > > module and have it defined as a public type, but when i go to call it from
> > > another workbook I get:
> > >
> > > "Compile error:
> > >
> > > Sub or Function not defined"
> > >
> > > Aside from coping the entire script into the new workbook is there a way to
> > > call a script stored in personal.xls from another workbook?
> > >
> > > Thanks!

> >
> > --
> >
> > Dave Peterson
> >


--

Dave Peterson
 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      18th May 2009
Or add a reference to that personal.xls workbook and just use the variable like
it's local to your project.

Dave Peterson wrote:
>
> The public variable is in personal.xls and you're trying to return that?
>
> If yes, then create a function in personal.xls and call that function:
>
> Function ReturnPublicVar1Val() as string 'variant, long, ...
> returnpublicvar1val = MyPublicVariableNameGoesHere
> end function
>
> jutlaux wrote:
> >
> > I used your application.run suggestion and this did work as needed. Thanks!
> >
> > I failed to mention that the script being called has a variable that returns
> > some information. When I use your suggestion the public variable that has
> > the information to be returned is empty. Thoughts?
> >
> > Thanks again.
> >
> > "Dave Peterson" wrote:
> >
> > > Dim pWkbk as workbook
> > > set pwkbk = workbooks("Personal.xls")
> > > application.run "'" & pwkb.name & "'!macronamehere", "parm1", "parm2"
> > >
> > > or if you're returning a value from a function:
> > >
> > > dim res as string 'or variant or long or ...
> > > res = application.run("'" & pwkb.name & "'!macronamehere", "parm1", "parm2")
> > >
> > > You could also create a reference to this personal.xls workbook and call it just
> > > like it was built into excel.
> > >
> > > Tools|references
> > > (but give the personal.xls's project a nice unique name (not VBAProject).
> > >
> > > ps.
> > >
> > > If you're using a function living in personal.xls inside a cell:
> > > =personal.xls!functionnamehere(a1,b1,c1)
> > >
> > > or save the file as an addin (*.xla) and use it in the cell like it's built into
> > > excel:
> > > =functionnamehere(a1,b1,c1)
> > >
> > >
> > >
> > >
> > >
> > > jutlaux wrote:
> > > >
> > > > I have a macro that is stored in my personal.xls that I would like to be able
> > > > to call from another workbook. I have the macro stored in a standard code
> > > > module and have it defined as a public type, but when i go to call it from
> > > > another workbook I get:
> > > >
> > > > "Compile error:
> > > >
> > > > Sub or Function not defined"
> > > >
> > > > Aside from coping the entire script into the new workbook is there a way to
> > > > call a script stored in personal.xls from another workbook?
> > > >
> > > > Thanks!
> > >
> > > --
> > >
> > > Dave Peterson
> > >

>
> --
>
> Dave Peterson


--

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
Call sub from Personal.xls don Microsoft Excel Programming 6 23rd Jun 2008 06:23 AM
How to Call Functions in the Personal Workbook? SteveM Microsoft Excel Programming 1 18th Dec 2007 03:07 PM
Custom button to call a macro in Personal David Walker Microsoft Excel Programming 1 1st Jul 2006 11:45 PM
Personal macro workbook and personal.xls =?Utf-8?B?Sm9obiBLaWxrZW5ueQ==?= Microsoft Excel Misc 1 14th Jun 2005 09:43 PM
Call a macro in my personal.xls Greg Rivet Microsoft Excel Misc 2 8th Jan 2004 06:42 PM


Features
 

Advertising
 

Newsgroups
 


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