devxlogo

Let the user insert OLE objects in a RichTextBox control

Let the user insert OLE objects in a RichTextBox control

A little-known feature of the RichTextBox control allows you to insert an OLE object in the text being edited. However, you can do so only programmatically, by adding an element to the OleObjects collection. An easy way to let the user select the object to be embedded in the control is using the InsertObjDlg method of the OLE Container object.

To test this functionality, drop a RichTextBox and an OLE control on a form (leaving their default names), add a cmdInsert button and write this code:

Private Sub cmdInsert_Click()    ' Show the InsertObject dialog    OLE1.InsertObjDlg    If Len(OLE1.Class) Then        ' If the user selected an object, show it in the RichTextBox control        RichTextBox1.OLEObjects.Add , , , OLE1.Class        OLE1.Class = ""    End IfEnd Sub

See also  How to Create and Deploy QR Codes Online: A Comprehensive Guide
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist