SetFocus again to Word Application after insert data to an Embedded excel sheet

With a word macro (VBA) I wrote data in cells of an Embedded excel sheet  in a word document. After this the macro makes some changes in word document itself. But the application focus is still on the Excel Application, not on the word application.
See also: http://www.experts-exchange.com/Applications/MS_Office/Word/Q_21140656.html
infofactoryAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
DRJConnect With a Mentor Commented:
Why activate the embedded object?

Sub EditSheet()
Dim Doc As Document
Dim wbk As Object
Dim wks As Object
Dim i As Integer
Set Doc = ActiveDocument
For i = 1 To Doc.InlineShapes.Count
    If Doc.InlineShapes(i).Type = wdInlineShapeEmbeddedOLEObject Then
        If Doc.InlineShapes(i).OLEFormat.ProgID = "Excel.Sheet.8" Then
            Set wbk = Doc.InlineShapes(i).OLEFormat.Object
            Set wks = wbk.Sheets("Sheet1")
            If wks Is Nothing Then
                MsgBox "Problem creating sheet object"
            Else
                wks.Range("A1") = "Top Left"
            End If
        End If
    End If
Next i
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument

End Sub
0
 
DRJCommented:
Just cut out this line from your previous code:

Doc.InlineShapes(i).OLEFormat.DoVerb wdOLEVerbPrimary
0
 
thydzikCommented:
just a note, DRJ's solution only works if the embedded object has previously been activated/edited.

if it hasn't you will get a run-time error '430'
0
All Courses

From novice to tech pro — start learning today.