Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 07-30-2019, 12:39 AM
Dzib Dzib is offline Copy / Paste from Excel to Word template Windows 10 Copy / Paste from Excel to Word template Office 2019
Novice
Copy / Paste from Excel to Word template
 
Join Date: Jul 2019
Posts: 29
Dzib is on a distinguished road
Default Copy / Paste from Excel to Word template

Hi,
I have this macro that copy paste a table from Excel to Word but I'd like to paste it into an existing Word document and at the end of it, after a title and another table.
The table is always inserted before the title...



Code:
Sub Export()

 

Dim wdApp As Object

Dim wd As Object

Dim xlSheet As Worksheet

Dim rng As Range

Dim LastRow As Long

Const wdReplaceAll As Long = 2

Const wdFindContinue As Long = 1

 

On Error Resume Next

Set wdApp = GetObject(, "Word.Application")

 

If Err.Number <> 0 Then

    Set wdApp = CreateObject("Word.Application")

End If

On Error GoTo 0

 

Set wd = wdApp.Documents.Add("C:\Users\446066523\Documents\Test.docx")

wdApp.Visible = True

 

Set xlSheet = ActiveWorkbook.Sheets("INV")

With xlSheet

    LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row

    Set rng = .Range("A2:C" & LastRow)

    rng.Copy

    With wd.Range

        .Collapse Direction:=0

        .InsertParagraphAfter

        .PasteSpecial DataType:=1

        With .Find

            .ClearFormatting

            .Text = vbTab

            .Replacement.ClearFormatting

            .Replacement.Text = " "

            .Execute Replace:=wdReplaceAll, Forward:=True, Wrap:=wdFindContinue

        End With

    End With

End With
End Sub
Reply With Quote
  #2  
Old 07-30-2019, 01:31 AM
Dzib Dzib is offline Copy / Paste from Excel to Word template Windows 10 Copy / Paste from Excel to Word template Office 2019
Novice
Copy / Paste from Excel to Word template
 
Join Date: Jul 2019
Posts: 29
Dzib is on a distinguished road
Default

Nevermind, it works
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Copy / Paste from Excel to Word template Copy & Paste Word Doc from Excel VBA RMerckling Excel Programming 4 04-18-2018 03:57 PM
Copy / Paste from Excel to Word template Copy/paste from Excel to Word problems! mross127 Word 10 08-16-2017 04:41 PM
Copy / Paste from Excel to Word template Copy/Paste EXCEL cells as pic in WORD A_Lau Drawing and Graphics 3 12-19-2014 06:57 AM
Copy / Paste from Excel to Word template Word 2007 Copy/Paste Excel issue raven26c Word 1 11-18-2011 02:49 AM
copy/paste charts from excel to word bielak01 Excel 0 04-16-2009 02:27 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 08:40 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft