Running Excel function from Access function/macro 
Author Message
 Running Excel function from Access function/macro

I've created a function in Excel.  I'd like to call that
function from another function or macro in Access.  For
example the Excel function is xlfunction(myarg).  While
Excel & Access are both open, I'd like to put in a call to
that function like xlfunction("abcd") so that xlfunction
will run with abcd as the value of myarg.
Is this possible and if so how?

Thank you muchly!



Wed, 07 Dec 2005 01:50:31 GMT  
 Running Excel function from Access function/macro
Carlos,

You may want to look at this article on MS's site.
http://support.microsoft.com/default.aspx?scid=kb;en-us;198571

Hope it helps.

-Rob


Quote:
> I've created a function in Excel.  I'd like to call that
> function from another function or macro in Access.  For
> example the Excel function is xlfunction(myarg).  While
> Excel & Access are both open, I'd like to put in a call to
> that function like xlfunction("abcd") so that xlfunction
> will run with abcd as the value of myarg.
> Is this possible and if so how?

> Thank you muchly!



Wed, 07 Dec 2005 02:34:51 GMT  
 Running Excel function from Access function/macro
Run Method Example

This example shows how to call the function macro My_Func_Sum, which is
defined on the macro sheet Mycustom.xlm (the macro sheet must be open). The
function takes two numeric arguments (1 and 5, in this example).

mySum = Application.Run("MYCUSTOM.XLM!My_Func_Sum", 1, 5)
MsgBox "Macro result: " & mySum
So xlApp.Application.Run("YOURWORKBOOKNAME.XLS!xlfunction",myarg) will work
from an Access module.
(as long as the function is public).
--

John

johnf202 at hotmail dot com


Quote:
> I've created a function in Excel.  I'd like to call that
> function from another function or macro in Access.  For
> example the Excel function is xlfunction(myarg).  While
> Excel & Access are both open, I'd like to put in a call to
> that function like xlfunction("abcd") so that xlfunction
> will run with abcd as the value of myarg.
> Is this possible and if so how?

> Thank you muchly!



Wed, 07 Dec 2005 03:33:56 GMT  
 Running Excel function from Access function/macro
jaf, your code is a bit on the long side as you don't have to call the
application object 2 different times.  In your examples

if in the Excel VBA and using the code:

Application.Run

It's the same as just calling on the

Run

method cause the application object is the application itself by default
just as the Application variable is the application that the code is in by
default.

however, since the xlApp is already the application object (provided that it
was set to Excel.Application in either the GetObject for the existing open
Excel instance or using the Set statement with the New keyword included for
a new instance of Excel.Application), one could just call on the Run method.

xlApp.Run("MyWorkbook.xls!Module1.MyFunction")

OR

xlApp.Run("MyWorkbook.xls!Module1.MyFunction", 1, 5)

will do the job just fine.

In my test, I have tried the following code and it works for me.

Sub AppTest()
    Dim ReportYear As Long
    Set XLApp = GetObject(, "Excel.Application")
    ReprtYear = XLApp.Run("ProdReportExec.xls!ProdReporting.ReportYear")
End Sub

The only catch to this that I have found, it must be in a Standard Module,
not a Class Module, and the function that this code is calling on must be
Public.

--
Ronald R. Dodge, Jr.
Production Statistician
Master MOUS 2000

Quote:
> Run Method Example

> This example shows how to call the function macro My_Func_Sum, which is
> defined on the macro sheet Mycustom.xlm (the macro sheet must be open).
The
> function takes two numeric arguments (1 and 5, in this example).

> mySum = Application.Run("MYCUSTOM.XLM!My_Func_Sum", 1, 5)
> MsgBox "Macro result: " & mySum
> So xlApp.Application.Run("YOURWORKBOOKNAME.XLS!xlfunction",myarg) will
work
> from an Access module.
> (as long as the function is public).
> --

> John

> johnf202 at hotmail dot com



> > I've created a function in Excel.  I'd like to call that
> > function from another function or macro in Access.  For
> > example the Excel function is xlfunction(myarg).  While
> > Excel & Access are both open, I'd like to put in a call to
> > that function like xlfunction("abcd") so that xlfunction
> > will run with abcd as the value of myarg.
> > Is this possible and if so how?

> > Thank you muchly!



Wed, 07 Dec 2005 04:14:49 GMT  
 Running Excel function from Access function/macro
8<0
It never hurts to be explicit.

--

John

johnf202 at hotmail dot com


Quote:
> jaf, your code is a bit on the long side as you don't have to call the
> application object 2 different times.  In your examples

> if in the Excel VBA and using the code:

> Application.Run

> It's the same as just calling on the

> Run

> method cause the application object is the application itself by default
> just as the Application variable is the application that the code is in by
> default.

> however, since the xlApp is already the application object (provided that
it
> was set to Excel.Application in either the GetObject for the existing open
> Excel instance or using the Set statement with the New keyword included
for
> a new instance of Excel.Application), one could just call on the Run
method.

> xlApp.Run("MyWorkbook.xls!Module1.MyFunction")

> OR

> xlApp.Run("MyWorkbook.xls!Module1.MyFunction", 1, 5)

> will do the job just fine.

> In my test, I have tried the following code and it works for me.

> Sub AppTest()
>     Dim ReportYear As Long
>     Set XLApp = GetObject(, "Excel.Application")
>     ReprtYear = XLApp.Run("ProdReportExec.xls!ProdReporting.ReportYear")
> End Sub

> The only catch to this that I have found, it must be in a Standard Module,
> not a Class Module, and the function that this code is calling on must be
> Public.

> --
> Ronald R. Dodge, Jr.
> Production Statistician
> Master MOUS 2000


> > Run Method Example

> > This example shows how to call the function macro My_Func_Sum, which is
> > defined on the macro sheet Mycustom.xlm (the macro sheet must be open).
> The
> > function takes two numeric arguments (1 and 5, in this example).

> > mySum = Application.Run("MYCUSTOM.XLM!My_Func_Sum", 1, 5)
> > MsgBox "Macro result: " & mySum
> > So xlApp.Application.Run("YOURWORKBOOKNAME.XLS!xlfunction",myarg) will
> work
> > from an Access module.
> > (as long as the function is public).
> > --

> > John

> > johnf202 at hotmail dot com



> > > I've created a function in Excel.  I'd like to call that
> > > function from another function or macro in Access.  For
> > > example the Excel function is xlfunction(myarg).  While
> > > Excel & Access are both open, I'd like to put in a call to
> > > that function like xlfunction("abcd") so that xlfunction
> > > will run with abcd as the value of myarg.
> > > Is this possible and if so how?

> > > Thank you muchly!



Wed, 07 Dec 2005 21:46:16 GMT  
 Running Excel function from Access function/macro
Thats pretty near what I need.  The problem is the article
describes access built-in and add-in functions.  I can't
figure out how to apply that to an Excel module/function
that I've built myself.
Any ideas/suggestions?

Thank you.

Quote:
>-----Original Message-----
>Carlos,

>You may want to look at this article on MS's site.
>http://support.microsoft.com/default.aspx?scid=kb;en-
us;198571

>Hope it helps.

>-Rob



>> I've created a function in Excel.  I'd like to call that
>> function from another function or macro in Access.  For
>> example the Excel function is xlfunction(myarg).  While
>> Excel & Access are both open, I'd like to put in a call
to
>> that function like xlfunction("abcd") so that xlfunction
>> will run with abcd as the value of myarg.
>> Is this possible and if so how?

>> Thank you muchly!

>.



Fri, 09 Dec 2005 23:00:33 GMT  
 Running Excel function from Access function/macro
After you have created your Excel Application variable, you can then use the
Run function on that variable either as a function to have your method
(Function only) to return a result, or as a sub procedure to execute your
method (Function or Sub).  See examples of both below:

Used as a function example:

MyVar = xlApp.Run("MyWorkbook.xls!Module1.MyFunction", 1, 5)

Used as an execution example:

xlApp.Run "MyWorkbook.xls!Module1.MyFunction", 1, 5

Note, when you call up your method, you must have it in the String format of
the syntax for your macro name argument:

<WorkbookFullName>!<ModuleName>.<MethodName>

FullName is the name of the file including the file 3 letter extension, but
excluding the path name to the file.

This does assume that this workbook is already openned in Excel.

Can not use Named arguement with the Run function (I.e. With the Open
function of the Excel application, Filename := "MyWorkbook.xls"), but rather
must put in the arguments in the same order and position as it is done in
the method.

--
Ronald R. Dodge, Jr.
Production Statistician
Master MOUS 2000

Quote:
> Thats pretty near what I need.  The problem is the article
> describes access built-in and add-in functions.  I can't
> figure out how to apply that to an Excel module/function
> that I've built myself.
> Any ideas/suggestions?

> Thank you.

> >-----Original Message-----
> >Carlos,

> >You may want to look at this article on MS's site.
> >http://support.microsoft.com/default.aspx?scid=kb;en-
> us;198571

> >Hope it helps.

> >-Rob



> >> I've created a function in Excel.  I'd like to call that
> >> function from another function or macro in Access.  For
> >> example the Excel function is xlfunction(myarg).  While
> >> Excel & Access are both open, I'd like to put in a call
> to
> >> that function like xlfunction("abcd") so that xlfunction
> >> will run with abcd as the value of myarg.
> >> Is this possible and if so how?

> >> Thank you muchly!

> >.



Fri, 09 Dec 2005 23:29:55 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. Running an Access macro or function

2. Problem in running Excel sort function in Access using VBA

3. Use of Excel functions in visual basic functions in excel module

4. Opening an excel file through a form/running excel macros through access

5. HowTo: Bind a Function Key to a Macro (or VBScript Function)

6. Convert Excel 4 Macro function to VBA

7. How do I use time function to activate a macro in Excel

8. UNDO Function in Excel Macro by Using VBA

9. Using VBA time functions with excel macro

10. How do I use time function to activate a macro in Excel

11. Excel, VB, and function macros

12. Function Macro for Excel 97

 

 
Powered by phpBB® Forum Software