leaving an embedded object (excel sheet) and returning back to word
Hi all,
i have been looking into this myself but cant find a way to make it work.
I have a word document with embedded excel tables (formulas, external references) and to make sure they get updated when the document is opened i wrote a bit of code to select them
<code>
For Each s In ActiveDocument.InlineShapes
If s.Type = wdInlineShapeEmbeddedOLEObject Then
If InStr(1, s.OLEFormat.ProgID, "Excel") Then
s.OLEFormat.Activate
End If
End If
Next
<\code>
This is executed upon opening the document. Problem is the focus stays on the last opened table and i cant find a way to release it.
Any help?
PS : this is word 2003
DeactivateOleObject: works for current version of Office 365 (2020)
Quote:
Originally Posted by
Marius Titul
This is more complicated then I thought.
I'm on it for over an hour and it still doesn't work.
I ran into this same issue with an OLE activated Excel object in Word, and I couldn't get the Excel OLE window to close.
The following works for me:
Code:
Private Sub DeactivateOleObject(ByRef olef As Word.OLEFormat)
On Error GoTo ErrorHandler
Call olef.ActivateAs("This.Class.Does.Not.Exist")
ErrorHandler:
End Sub
Then the above sub can be used like:
Code:
Dim MyShape As InlineShape
Set MyShape = wordDocumentInstance.Bookmarks(key).Range.InlineShapes.AddOLEObject(ClassType:="Excel.Sheet")
'Do some stuff with OLE object
DeactivateOleObject MyShape.OLEFormat
Note: since the OLE object was created by Word, the data type of the "olef" parameter in the subroutine above is defined as "Word.OLEFormat". If this was the reverse, and an OLE object was created by Excel, then the type would be "Excel.OLEFormat". If you indicate the wrong type for that parameter, then you will get a Type Mismatch error.