Hi
I am using the following procedure to paste something to a Word document.
I need to run the procedure several times. How do I update the code so that
it checks if the Word document is already open and doesn't reopen it.
Sub PasteToWord2(ByVal strFilePath As String)
On Error GoTo EH
Dim wdApp As Object
Dim i As Integer
On Error Resume Next
Set wdApp = GetObject(, "Word.Application")
If Err.Number <> 0 Then
Set wdApp = CreateObject("Word.Applica
tion")
End If
On Error GoTo 0
With wdApp
.Visible = True
Set wdDoc = .Documents.Open( _
Filename:=strFilePath, ReadOnly:=False)
End With
'Range(strRange).CopyPictu
re xlScreen, xlPicture 'use if you need to copy Excel range is a pic in this procedure
wdDoc.Range.past
wdDoc.Save
wdDoc.Close
wdApp.Quit
'clean up
Set wdDoc = Nothing
Set wdApp = Nothing
Exit Sub
EH:
MsgBox "There was a problem pasting to a word document!"
End Sub
Start Free Trial