Visual Basic Concepts
By displaying the Paste Special and Insert Object dialog boxes at run time, you can allow the user to create a variety of objects. You may do this when creating a document-centered application. In such an application, the user combines data from different applications to create a single document. For instance, this application might be a word processor in which the user might enter some text and then embed a spreadsheet and a chart using the Insert Object or Paste Special dialog box.
You use the OLE container control's InsertObjDlg method to display the Insert Object dialog box, or you can use the PasteSpecialDlg method to display the Paste Special dialog. These two dialogs let the user make decisions about what goes into the OLE container control.
You can display these dialog boxes at run time by calling the appropriate method on an event — for instance, a menu's Click event:
Private Sub cmdInsert_Click ()
' Display Insert Object dialog box.
oleObj1.InsertObjDlg
' Check to make sure object was created with the
' OLEType property.
If oleObj1.OLEType = vbOLENone Then
MsgBox "Object Not Created."
End If
End Sub
Private Sub oleObj1_Click ()
' Determine if the data contained on the Clipboard
' can be pasted into the OLE container control.
If oleObj1.PasteOK Then
' Display Paste Special dialog box.
oleObj1.PasteSpecialDlg
' Check to make sure object was created.
If oleObj1.OLEType = vbOLENone Then
MsgBox "Object Not Created."
End If
End If
End Sub
Once the dialog box is displayed, you do not need to write more code to create the object. The user makes choices in the dialog box and chooses OK to create an object. If the user cancels a dialog, an object is not created.
Note Before displaying the Insert Object or Paste Special dialog box, you may want to determine the value of the OLEType property to see if the OLE container control contains a linked object, embedded object, or no object, as demonstrated in the preceding code example.
The constant vbOLENone and other intrinsic constants are listed in the Visual Basic (VB) object library of the Object Browser.