Solved

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

Posted on 2004-10-03
7
388 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
This is written from a 'VBA for MS Word' perspective, but I am sure it applies to most other MS Office components where VBA is used.  One thing that really bugs me is slow code, ESPECIALLY when it's mine!  In programming there are so many ways to…
This video teaches the viewer how to align pictures around text while keeping the text properly aligned in the document.
This video walks the viewer through the process of creating envelopes and labels, with multiple names and addresses. Navigate to the “Start Mail Merge” button in the Mailings tab: Follow the step-by-step process until asked to find the address doc…

624 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