Uploaded according to topic, I think you've helped me a lot.
I uploaded another similar but not the same topic.
However I have indicated that I must continue this same thread
therefore I will repeat what I put there.
With your code I have a way to recognize if the file is closed ered or, to paste a range of excel. If the arcchivo is closed, the macro works fine, but if it is open, there is when I have problems.
This is what I wrote in the other thread:
........." paste this code range MyWord file excel in this closed, then opens it and displays it."
Code:
Private Sub CommandButton1_Click()
Hoja8.Range("A1:H32").Select
Selection.CopyPicture xlScreen, xlPicture
Archivo = ThisWorkbook.Path & "\Microbiologia I.docx"
With CreateObject("word.application")
Selection.CopyPicture xlScreen, xlPicture
.Documents.Open Archivo
.Selection.Paste
.ActiveDocument.SaveAs (Archivo)
.Visible = True
.Activate
End With
End Sub
But what if I want to paste into MyWord file that is already open ???
Error generates the code shown here:
File .Documents.Open (fn)
Because attempts to open a file that is already open.
I tried with the code that the master Jindon, kindly helped me but also it does not work, especially if the file is already open.
Code:
Private Sub CommandButton1_Click()
Dim fn As String, myWord As Object
fn = ThisWorkbook.Path & "\Microbiologia I.docx"
With GetObject(, "word.application")
If IsFileOpen(fn) Then 'File is open
Hoja8.Range("A1:H32").Select
Selection.CopyPicture xlScreen, xlPicture
fn = Split(fn, "\")(UBound(Split(fn, "\")))
'Set myWord =
.Documents (fn)
.Selection.Paste
.ActiveDocument.SaveAs (fn)
Else 'If file es closed
Hoja8.Range("A1:H32").Select
Selection.CopyPicture xlScreen, xlPicture
'Set myWord =
.Documents.Open (fn)
.Selection.Paste
' CreateObject("word.application")
.ActiveDocument.SaveAs (fn)
.Visible = True
.Activate
End If
End With
MsgBox myWord.Name 'Ready!!
End Sub
How do I get my file already open,... and copy paste my rang?
I anticipate my thanks