
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!
> >.