ACC: Sample OLE Automation for MS Word and MS Excel
ID: Q123859
|
The information in this article applies to:
-
Microsoft Access versions 2.0, 7.0, 97
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:
- Create a form based on the table containing the MyOle field.
- Add a bound object frame with the following properties to the form:
Name: MyOle
ControlSource: MyOle
- 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:
- Create a form based on the table containing theMy_excel_ole field.
- Add a bound object frame with the following properties to the form:
Name: My_excel_ole
ControlSource: My_excel_ole
- 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.
Additional query words:
Keywords : kbole IntpOlea
Version : WINDOWS:2.0,7.0,97
Platform : WINDOWS
Issue type : kbinfo