irisqueiroz
Member
I'd like to know how to create a code to export a range in Excel to a Word document that already exists. The issue here is that the Excel range has to be pasted in the end of the Word document. I have a code that pastes it in the begining.
Thanks!
Code:
Sub createWord()
Dim WdObj As Object, fname As String
fname = "Word"
Set WdObj = CreateObject("Word.Application")
WdObj.Visible = False
Range("A1:I30").Select
Selection.Copy 'Your Copy Range
WdObj.Documents.Open Filename:="U:\risco\Gestao de Suitability\Disparo Desenquadramentos\Carta_Cliente.docx"
WdObj.Selection.PasteSpecial Link:=False, DataType:=wdPasteText, Placement:=wdInLine, DisplayAsIcon:=False
Application.CutCopyMode = False
If fname <> "" Then 'make sure fname is not blank
With WdObj
.ChangeFileOpenDirectory "U:\risco\Gestao de Suitability\Disparo Desenquadramentos" 'save Dir
.ActiveDocument.SaveAs Filename:=fname & ".doc"
End With
Else:
MsgBox ("File not saved, naming range was botched, guess again.")
End If
With WdObj
.ActiveDocument.Close
.Quit
End With
Set WdObj = Nothing
End Sub
Thanks!