Hoe to make multiple updates from excel to word without having to save and close word every time?

Posted on 2007-08-01
Last Modified: 2011-10-03
How do I make updates to my word doc while it is open without getting the message that the doc is read only becasue it is in use without have to save and close it after every update?

Sub EditOLE()
   Dim objOLE As Object
   Dim appWord As Object
   Dim docWord As Object
   Dim shp As Object
   Set appWord = CreateObject("Word.Application")
   Set docWord = appWord.Documents.Open("C:\Tom Brown\TestWord.doc")
   appWord.Visible = True
   Set shp = docWord.InlineShapes(1)
   Set objOLE = shp.OLEFormat.Object
   objOLE.Worksheets(1).Range("A1").PasteSpecial xlPasteAll
   'docWord.Close True
End Sub
Question by:tlbdst
    LVL 4

    Expert Comment

    Application.DisplayAlerts = False  

    will ignore any prompts by excel.  put it befor you open the doc...


    Author Comment

    How do I do this conditional based upon whether the word doc is open or not?

    Author Comment

    I want to be able to make an update using the VBA sub routine without having to worry about whether the document is already open or not.  Some of the problems I have are:
    1. The doc is locked for editing with the option to open it as read only.
    2. Run-time error '-1073741819 (c000005).  Automation Error
    LVL 92

    Accepted Solution

    You could try this:

    ' see if Word is already running
    On Error Resume Next
    Set appWord = GetObject(, "Word.Application")
    If Err <> 0 Then
        'Word was not running
        Set appWord = CreateObject("Word.Application")
        Set docWord = appWord.Documents.Open("C:\Tom Brown\TestWord.doc")
        'Word was running; see if doc is open in that instance
        Set docWord = appWord.Documents("C:\Tom Brown\TestWord.doc")
        If Err <> 0 Then
            'doc was not open
            Set docWord = appWord.Documents.Open("C:\Tom Brown\TestWord.doc")
        End If
    End If
    On Error GoTo 0

    This can still fail if you have multiple instances of Word open, of course...
    LVL 1

    Expert Comment

    Forced accept.

    EE Admin

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    Excel sending an email 5 40
    Sending email from Excel 2016 VBA and Outlook 2016 4 33
    Sum Per Month 7 23
    Search Box 13 29
    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…
    Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
    Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.
    This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

    729 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

    18 Experts available now in Live!

    Get 1:1 Help Now