Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2004-10-03
7
Medium Priority
?
389 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 500 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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

I would like to show you some basics you can do with Mailings in MS Word. It´s quite handy feature you can use for creating envelopes, labels, personalized letters etc. First question could be what is this feature good for? Mailing can really he…
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.
The viewer will learn how to make their project stand out over others by learning how to change colors and shapes, add spaces, change directions, and add bullets to their charts.

721 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