The information in this article applies to:
SUMMARY
You can use Automation to run a Microsoft Visual Basic for Applications Sub
procedure that exists in a document of another Microsoft Office program.
This article shows you how to run Sub procedures from four of the Microsoft
Office programs that support Visual Basic (Microsoft Access, Microsoft
Excel, Microsoft PowerPoint, and Microsoft Word). Although some of these
programs previously had their own macro languages (Excel 4.0 Macro
Language, Access Basic, WordBasic), this article only discusses running
Visual Basic Sub procedures.
MORE INFORMATIONMicrosoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support professionals can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific needs. If you have limited programming experience, you may want to contact the Microsoft fee-based consulting line at (800) 936-5200. For more information about the support options available from Microsoft, please see the following page on the World Wide Web: http://www.microsoft.com/support/supportnet/overview/overview.aspThe products listed at the beginning of this article all have very similar means of accessing a Sub procedure stored in their respective file formats. The following Sub procedures should work in any of the Microsoft Office programs. Any differences are noted. To use any of these Sub procedures, you must place them in a module. Follow these steps to insert a module for the appropriate program. Inserting a Module in Excel, PowerPoint or Word
Inserting a Module in Microsoft Access
Sub Procedure to Run an Existing Microsoft Access MacroThe following Sub procedure assumes that the database AccessAutomation.mdb contains a macro called "AccessMacro."
There are a couple of things to note when calling a Microsoft Access macro.
First, when you use the CreateObject function to create an instance of
Microsoft Access, it is always created as visible. All of the other
Microsoft Office programs are created with the Visible property set to
False by default.
Also, note that if a Microsoft Access Sub procedure displays a modal dialog box, such as a message box, Microsoft Access has to be activated manually using the Microsoft Windows 95 taskbar to view the dialog box. If the code does not display a modal dialog box, manual activation is not necessary. There is no way to do this activation programmatically with Automation. All of the other programs listed at the beginning of this article display dialog boxes without being activated. Sub Procedure to Run an Existing Microsoft Excel MacroThe following Sub procedure assumes that the workbook ExcelFile.xls contains a macro called "TestMacro."
Sub Procedure to Run an Existing Microsoft PowerPoint MacroThe following Sub procedure assumes that the presentation PPTAutomation.ppt contains a macro called "AutomationTest."
Sub Procedure to Run an Existing Microsoft Word MacroThe following Sub procedure assumes that the document WordDoc.Doc contains a macro called "WordMacro."
REFERENCESFor additional information, please see the following articles in the Microsoft Knowledge Base: Q165518Calling Macros Using OLE from MS Visual Basic for Applicatons Q153307HOWTO: Call Microsoft Excel Macros that Take Parameters Q128405 XL: How to Run a WordBasic Macro from an MS Excel MacroFor more information about getting help with Visual Basic for Applications, please see the following article in the Microsoft Knowledge Base: Q163435 VBA: Programming Resources for Visual Basic for Applications Additional query words: vba
Keywords : kbcode kbmacro kbprg |
Last Reviewed: November 13, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |