Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #3  
Old 08-27-2019, 02:16 PM
Dzib Dzib is offline Export data to word table Windows 10 Export data to word table Office 2019
Novice
Export data to word table
 
Join Date: Jul 2019
Posts: 29
Dzib is on a distinguished road
Default

Thanks Kenneth, here's my code:


Code:
Sub ExportInvNL()

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\laure\Documents\Boulot\TestInventarisNL.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:=3
        With .Find
            .ClearFormatting
            .Text = vbTab
            .Replacement.ClearFormatting
            .Replacement.Text = " "
            .Execute Replace:=wdReplaceAll, Forward:=True, Wrap:=wdFindContinue
        End With
    End With
End With

End Sub
Works perfect with


Code:
wd.Tables(2).Cell(2, 3).Range = Range("A1")

Thanks mate
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro to export a table to Word Dzib Excel Programming 2 07-28-2019 02:36 AM
Export data to word table VBA Export Data as Text from Excel to Word lwbarnes Word VBA 3 06-09-2016 02:47 PM
Export data to word table Export Word Form Data to Access pboland Word VBA 1 06-12-2015 06:53 PM
Export data to word table Export data from C# winForms treeView to MS-Word MergeFields nisim651 Mail Merge 8 04-18-2014 04:17 AM
Microsoft word table export ? -need help- --alexander-- Word 2 04-17-2013 11:13 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 10:33 AM.


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