Article ID: 181889
Article Last Modified on 1/22/2007
OLE1.DoVerb vbOLEOpenAnother workaround is to deactivate the object before calling the automation code that causes Visual Basic to hang. For example, the PrintOut and Delete methods cause this problem to occur. Before using these methods, you can deactivate the object prior to calling the method, then optionally reactivate the object after calling the method. See the MORE INFORMATION section later in this article for an example.
| Property | Value |
|---|---|
| Name | OLE1 |
| Class | Excel.Sheet.8 |
Private Sub Command1_Click()
Dim xlBook As Excel.Workbook
Set xlBook = OLE1.object
OLE1.DoVerb vbOLEShow 'or OLE1.DoVerb vbOLEUIActivate
xlBook.Worksheets("Sheet1").Range("A1").Value = "Hello"
xlBook.Worksheets("Sheet1").PrintOut
Set xlBook = Nothing
End Sub
Private Sub Command1_Click()
Dim xlBook As Excel.Workbook
Set xlBook = OLE1.object
OLE1.DoVerb vbOLEShow 'or OLE1.DoVerb vbOLEUIActivate
xlBook.Worksheets("Sheet1").Range("A1").Value = "Hello"
Command1.SetFocus 'causes deactivation of object
xlBook.Worksheets("Sheet1").PrintOut
OLE1.DoVerb vbOLEShow 'optional: reactivates object
Set xlBook = Nothing
End Sub
The problem is avoided by deactivating the object before calling the
PrintOut method. Setting focus to any control on the form will deactivate
the OLE control object.Additional query words: locks freezes crashes
Keywords: kbbug kbctrl kbpending KB181889