VBA Export to Word Table

Tuckshop

New Member
Joined
Aug 26, 2002
Messages
5
I am attempting to export an array from Excel into a Word table.

I have included my code below, I get a new instance of word but that's where it ends?

Can anyone confirm what I have missed...


Dim objWord As Object
Set objWord = New Word.Application
objWord.Visible = True
objWord.Documents.Add
objWord.EndKey Unit:=wdStory
objWord.TypeParagraph
ActiveDocument.Tables.Add Range:=Selection.Range, numrows:=1, numcolumns:= 9,_ DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:= _
wdAutoFitContent
With Selection.Tables(1)
If .Style <> "Table Grid" Then
.Style = "Table Grid"
End If
.ApplyStyleHeadingRows = True
.ApplyStyleLastRow = True
.ApplyStyleFirstColumn = True
.ApplyStyleLastColumn = True
End With

Selection.Tables(1).Select
Selection.SelectCell
Selection.TypeText Text:="Contract #"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="Narrative 1"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="Narrative 2"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="St Date"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="Fi Date"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="Contract Type"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="Budget Sale"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="Actual Sale"
Selection.MoveRight Unit:=wdCell
Selection.TypeText Text:="Balance"

<not included array loop, any help here would be an advantage to this new recruit..

Thank you...
 

Some videos you may like

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.

Andrew Poulsom

MrExcel MVP
Joined
Jul 21, 2002
Messages
73,092
Just a thought.

According to Help the Range argument of the Add method (Tables collection) specifies the range where you want the table to appear not the source range in Excel.

I think you will need to use Excel Copy and Word PasteSpecial.
 

Watch MrExcel Video

Forum statistics

Threads
1,118,111
Messages
5,570,257
Members
412,313
Latest member
pauloalex
Top