Solved

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

Posted on 2004-10-03
7
383 Views
Last Modified: 2012-06-22
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
0
Comment
Question by:infofactory
  • 2
7 Comments
 
LVL 6

Accepted Solution

by:
DRJ earned 125 total points
ID: 12215193
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
 
LVL 6

Expert Comment

by:DRJ
ID: 12215195
Just cut out this line from your previous code:

Doc.InlineShapes(i).OLEFormat.DoVerb wdOLEVerbPrimary
0
 
LVL 11

Expert Comment

by:thydzik
ID: 22100400
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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Authors who set out to write any sort of lengthy piece for online submission—be it a long question or comment on a technical form, an article, or a substantial blog entry—often find it useful to work up a draft in an editor other t…
Using Word 2013, I was experiencing some incredible lag when typing.  Here's what worked for me....
This video walks the viewer through the process of creating an MLA formatted document, as well as a bibliography with citations.
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now