Solved

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

Posted on 2004-10-03
7
382 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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

The Selection object is designed for user interaction. It has a Range property, so it can be used in most places that a Range object can. Recorded macros must use the Selection because they are simply copying what the user is doing. A Range prope…
Shortcuts in Word Just the other day I had a training for Microsoft and they wanted me to show how well the new Windows and Office behaved on a touch device, which by the way is great, but it was only then that I realized that using keyboard shortc…
In this video, we show how to convert an image-only PDF file into a PDF Searchable Image file, that is, a file with both the image (typically from scanning) and text, which is created in an automated fashion with Optical Character Recognition (OCR) …
This video walks the viewer through the process of creating an MLA formatted document, as well as a bibliography with citations.

747 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

12 Experts available now in Live!

Get 1:1 Help Now