ACC: Sample OLE Automation for MS Word and MS Excel

Last reviewed: November 13, 1997
Article ID: Q123859
The information in this article applies to:
  • Microsoft Access version 2.0, 7.0

SUMMARY

Moderate: Requires basic macro, coding, and interoperability skills.

This article demonstrates how to activate Microsoft Word version 6.0 for Windows or Microsoft Excel version 5.0 for Windows from a command button on a Microsoft Access form.

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 the "Building Applications" manual.

NOTE: Visual Basic for Applications (used in Microsoft Access version 7.0) is called Access Basic in version 2.0.

MORE INFORMATION

How to Activate Microsoft Word

The following example assumes a Microsoft Access table with an OLE object field called MyOle that contains embedded (not linked) Microsoft Word 6.0 objects. The example demonstrates how to create a command button that will activate Microsoft Word 6.0 in Normal view with the current Microsoft Word 6.0 object:

  1. Create a form based on the table containing the MyOle field.

  2. Add a bound object frame with the following properties to the form:

          Name: MyOle
          ControlSource: MyOle
    

  3. Add a command button named Button2 to the form. Set the button's OnClick property to the following event procedure:

          Sub Button2_Click ()
             Dim Word_Obj As Object
             me!MyOle.verb = -2
             me!MyOle.action = 7
             Set Word_Obj = MyOle.object.application.wordbasic
             Word_Obj.ViewNormal
          End Sub
    
    

How to Activate Microsoft Excel

The following example assumes a Microsoft Access table with an OLE object field called My_excel_ole that contains embedded (not linked) Microsoft Excel 5.0 objects. The example demonstrates how to create a command button that will activate Microsoft Excel with the current Microsoft Excel object:

  1. Create a form based on the table containing theMy_excel_ole field.

  2. Add a bound object frame with the following properties to the form:

          Name: My_excel_ole
          ControlSource: My_excel_ole
    

  3. Add a command button named Button3 to the form. Set the button's OnClick property to the following event procedure:

          Sub Button3_Click ()
             My_excel_ole.class = “Excel.Sheet”
             My_excel_ole.verb = -2
             My_excel_ole.action = 7
          End Sub
    
    

REFERENCES

Microsoft Access "Building Applications," version 2.0, Chapter 13, "Communicating with Other Applications," pages 282-297

For additional information about OLE Automation, search for "OLE Automation," and then "Interoperability with Microsoft Word and Microsoft Excel (Common Questions)" using the Microsoft Access Help menu.

Keywords          : kbole IntpOleA
Technology        : kbole
Version           : 2.0 7.0
Platform          : WINDOWS
Hardware          : x86
Issue type        : kbinfo


================================================================================


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: November 13, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.