Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 310
  • Last Modified:

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

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
1 Solution
Application.DisplayAlerts = False  

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

tlbdstAuthor Commented:
How do I do this conditional based upon whether the word doc is open or not?
tlbdstAuthor Commented:
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
Patrick MatthewsCommented:
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...
Forced accept.

EE Admin

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now