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

x
  • 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
   Selection.Copy
   Set appWord = CreateObject("Word.Application")
   Set docWord = appWord.Documents.Open("C:\Tom Brown\TestWord.doc")
   appWord.Visible = True
   ActiveSheet.Range("A1:D10").Copy
   Set shp = docWord.InlineShapes(1)
   shp.Activate
   Set objOLE = shp.OLEFormat.Object
   objOLE.Worksheets(1).Range("A1").PasteSpecial xlPasteAll
   'docWord.Close True
   'appWord.Quit
End Sub
0
tlbdst
Asked:
tlbdst
1 Solution
 
sublimationCommented:
Application.DisplayAlerts = False  

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

0
 
tlbdstAuthor Commented:
How do I do this conditional based upon whether the word doc is open or not?
0
 
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
0
 
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
    Err.Clear
    Set appWord = CreateObject("Word.Application")
    Set docWord = appWord.Documents.Open("C:\Tom Brown\TestWord.doc")
Else
    '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
        Err.Clear
        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...
0
 
Computer101Commented:
Forced accept.

Computer101
EE Admin
0

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