Visor
Member
Greetings friends of the forum, paste this code range MyWord file excel in this closed, then opens it and displays it.
But what if I want to paste into MyWord file that is already open ???
Error generates the code shown here:
File .Documents.Open
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.
How do I get my file already open,... and copy paste my rang?
I anticipate my thanks
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
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 (Archivo)
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 (Archivo)
.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