• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Export table from Excel to Word

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.

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!
 

Just before PasteSpecial line : WdObj.Selection.EndKey wdStory

As you could find out yourself by using Macro Recorder in Word ‼ :rolleyes:
 
Back
Top