Bill Hamilton
Board Regular
- Joined
- Mar 30, 2004
- Messages
- 95
Hi,
I have a macro that opens a Word doc to paste some data into it from the current Excel sheet. I have the following pretty standard code to set up the Word environment and open the document.
This works fine if the doc file exists and is not currently open, but just seems to hang if it is currently open. How can I allow for that, and use that instance of it anyway (and also not close it at the end)?
Also, what's the handling process for when/if the file doesn't exits (i.e. not found)? Is there a specific Err.Number value I should check for?
Any help would be appreciated.
Bill
I have a macro that opens a Word doc to paste some data into it from the current Excel sheet. I have the following pretty standard code to set up the Word environment and open the document.
Code:
Sub UpdateWordDoc()
Dim wdDoc As Object, wdApp As Object
Set wdApp = CreateObject("word.application")
Set wdDoc = wdApp.Documents.Open(ThisWorkbook.Path & Application.PathSeparator & "info12.docx")
With wdDoc
' processing
End With
wdDoc.Close savechanges:=true
wdApp.Quit
Set wdDoc = Nothing
Set wdApp = Nothing
End Sub
This works fine if the doc file exists and is not currently open, but just seems to hang if it is currently open. How can I allow for that, and use that instance of it anyway (and also not close it at the end)?
Also, what's the handling process for when/if the file doesn't exits (i.e. not found)? Is there a specific Err.Number value I should check for?
Any help would be appreciated.
Bill