Article ID: 153748 - Last Review: January 19, 2007 - Revision: 3.3 ACC: How to Call Excel Functions from Within Microsoft AccessThis article was previously published under Q153748 Advanced: Requires expert coding, interoperability, and multiuser skills.
For a Microsoft Access 2000 version of this article, see 198571 (http://support.microsoft.com/kb/198571/EN-US/ ) . On This PageSUMMARY
This article shows you how to use Automation to call Microsoft Excel
functions from within Microsoft Access.
This article assumes that you are familiar with Visual Basic for Applications and with creating Microsoft Access applications using the programming tools provided with Microsoft Access. For more information about Visual Basic for Applications, please refer to your version of the "Building Applications with Microsoft Access" manual. MORE INFORMATION
Microsoft Excel offers some functions that are not available in Microsoft
Access, for example, statistical functions. However, you can access these
functions from within Microsoft Access by using Automation if you first set
a reference to the Microsoft Excel object library.
To create a reference to the Microsoft Excel object library, follow these steps:
The following two sample subroutines use Microsoft Excel statistical functions. NOTE: Microsoft Excel does not automatically close after it has been opened by using Automation. The following subroutines use the Quit method to close Microsoft Excel. For more information about quitting Microsoft Excel, please see the following article in the Microsoft Knowledge Base: 145770
(http://support.microsoft.com/kb/145770/EN-US/
)
ACC: Automation Does Not Close Microsoft Excel
Example 1The following subroutine uses Automation to call the Microsoft Excel Median() function. Half of the set of numbers fall below and half above the median.If you are using Microsoft Access 97 with Microsoft Excel 97, you can simplify the code by calling the Microsoft Excel reference directly: Example 2The following subroutine uses Automation to call the Microsoft Excel ChiInv() function, which returns the inverse or the one-tailed probability of the Chi-Squared distribution:If you are using Microsoft Access 97 with Microsoft Excel 97, you can simplify the code by calling the Microsoft Excel reference directly: Microsoft Excel also uses add-ins. These are programs that include custom functions and commands. If you need to use a function included in an add-in program, you must first open the add-in. The following is an example of using the LCM (Least Common Multiple) function: REFERENCES
For more information about using Automation, search for Automation, and
then Automation with Microsoft Access using the Microsoft Access 97 Help
Index.
For more information about using the Object Browser, search for Object Browser and then "Work with objects in Visual Basic using the Object Browser" using the Microsoft Access 97 Help Index. For more information about referencing type libraries, search for Type Libraries, and then "Set References to Type Libraries" using the Microsoft Access 97 Help Index. For more information about add-ins in Microsoft Excel, search for "add-in programs" using the Microsoft Excel 97 Help Index. | Article Translations
|


Back to the top
