Table of contents

CustomControl.Object 属性 (访问)CustomControl.Object Property (Access)

office 365 dev account|上次更新日期: 2018/3/13
2 参与人员

在 Visual Basic 中,可以使用对象属性返回与控件中的链接或嵌入的 OLE 对象相关联的 ActiveX 对象的引用。使用此引用,可以访问的属性,或者调用 OLE 对象的方法。只读对象You can use the Object property in Visual Basic to return a reference to the ActiveX object that is associated with a linked or embedded OLE object in a control. By using this reference, you can access the properties or invoke the methods of the OLE object. Read-only Object.


表达式对象expression. Object

表达式_一个表示CustomControl对象的变量。_expression A variable that represents a CustomControl object.


Object属性返回对 ActiveX 对象的引用。您可以使用Set语句将此 ActiveX 对象分配给对象变量。返回的对象引用的类型取决于创建 OLE 对象的应用程序。The Object property returns a reference to an ActiveX object. You can use the Set statement to assign this ActiveX object to an object variable. The type of object reference returned depends on which application created the OLE object.

当嵌入或链接 OLE 对象在 Microsoft Access 窗体中的时,可以设置属性,以确定对象的类型和容器控件的行为。但是,您不能直接设置或读取 OLE 对象的属性或应用它的方法,您可以执行自动化时。Object属性返回代表链接或嵌入的 OLE 对象的自动化对象的引用。使用此引用,可以通过设置或读取其属性或应用它的方法来更改 OLE 对象。例如,Microsoft Excel 将支持自动化的 COM 组件。如果在 Microsoft Access 窗体中嵌入的 Microsoft Excel 工作表,可以使用对象属性设置为与该工作表的工作表对象的引用。然后可以使用的任何属性和方法的工作表对象。When you embed or link an OLE object in a Microsoft Access form, you can set properties that determine the type of object and the behavior of the container control. However, you can't directly set or read the OLE object's properties or apply its methods, as you can when performing Automation. The Object property returns a reference to an Automation object that represents the linked or embedded OLE object. By using this reference, you can change the OLE object by setting or reading its properties or applying its methods. For example, Microsoft Excel is an COM component that supports Automation. If you've embedded a Microsoft Excel worksheet in a Microsoft Access form, you can use the Object property to set a reference to the Worksheet object associated with that worksheet. You can then use any of the properties and methods of the Worksheet object.

有关 ActiveX 对象支持的属性和方法的详细信息,请参阅用于创建 OLE 对象的应用程序的文档。For information on which properties and methods an ActiveX object supports, see the documentation for the application that was used to create the OLE object.


下面的示例使用名为 OLE1 的未绑定的对象框的对象属性。客户名称和地址信息将插入在嵌入的 Microsoft Word 文档格式设置为与中文本的名称和地址信息和可反复套用信函正文占位符套用信函中。过程将替换每条记录的占位符信息,然后打印套用信函。它不会保存打印的套用信函的副本。The following example uses the Object property of an unbound object frame named OLE1. Customer name and address information is inserted in an embedded Microsoft Word document formatted as a form letter with placeholders for the name and address information and boilerplate text in the body of the letter. The procedure replaces the placeholder information for each record and prints the form letter. It doesn't save copies of the printed form letter.

Sub PrintFormLetter_Click() 
 Dim objWord As Object 
 Dim strCustomer As String, strAddress As String 
 Dim strCity As String, strRegion As String 

 ' Assign object property of control to variable. 
 Set objWord = Me!OLE1.Object.Application.Wordbasic 
 ' Assign customer address to variables. 
 strCustomer = Me!CompanyName 
 strAddress = Me!Address 
 strCity = Me!City &; ", " 
 If Not IsNull(Me!Region) Then 
 strRegion = Me!Region 
 strRegion = Me!Country 
 End If 
 ' Activate ActiveX control. 
 Me!OLE1.Action = acOLEActivate 
 With objWord 
 ' Go to first placeholder. 
 .LineDown 2 
 ' Highlight placeholder text. 
 .EndOfLine 1 
 ' Insert customer name. 
 .Insert strCustomer 
 ' Go to next placeholder. 
 ' Highlight placeholder text. 
 .EndOfLine 1 
 ' Insert address. 
 .Insert strAddress 
 ' Go to last placeholder. 
 ' Highlight placeholder text. 
 .EndOfLine 1 
 ' Insert City and Region. 
 .Insert strCity &; strRegion 
 End With 
 Set objWord = Nothing 
End Sub

另请参阅See also


CustomControl 对象CustomControl Object

© 2018 Microsoft