How to call Excel functions from within Access 2000
This article was previously published under Q198571 On This PageSUMMARY This article shows you how to use Automation to call
Microsoft Excel functions from within Microsoft Access. Microsoft Excel has some functions that Microsoft Access does not have, for example, statistical functions and add-in functions. By using Automation, you can use these Excel functions in Access. To do so, first set a reference to the Microsoft Excel object library. Setting a Reference to the Microsoft Excel Object Library
The following two sample procedures use Microsoft Excel statistical functions. NOTE: Excel does not automatically close after you open it through Automation. The following sample procedures use the Quit method to close Excel. For additional information about quitting Excel, please see the following article in the Microsoft Knowledge Base: 210129 (http://support.microsoft.com/kb/210129/EN-US/) ACC2000: Applications Run from Automation Do Not Always Close
Example 1The following subroutine uses Automation to call the Excel Median() function. Half of the set of numbers fall below and half above the median. The subroutine displays 6.5 in a message box.Example 2The following subroutine uses Automation to call the Excel ChiInv() function, which returns the inverse, or the one-tailed probability, of the Chi-Squared distribution: The subroutine displays 18.3070290368475 in a message box. You can simplify the code by calling the Excel reference directly: NOTE: When you use this syntax, Excel remains in memory until you reset
the code or close the database.Using Add-insExcel also uses add-ins. These programs include custom functions and commands. If you need to use a function included in an add-in program, first open the add-in. The following example uses the LCM (Least Common Multiple) function: The subroutine displays 10 in a message box. REFERENCESFor more information about Automation, in the
Visual Basic Editor, click Microsoft Visual Basic Help on the Help menu, type automation in the Office Assistant or the Answer Wizard, and then click Search to view the topic. For more information about the Object Browser, in the Visual Basic Editor, click Microsoft Visual Basic Help on the Help menu, type browser in the Office Assistant or the Answer Wizard, and then click Search to view the topic. For more information about referencing type libraries, in the Visual Basic Editor, click Microsoft Visual Basic Help on the Help menu, type set references in the Office Assistant or the Answer Wizard, and then click Search to view the topic.
| Article Translations
|
Back to the top
