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...
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
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.
 
Upvote 0

Forum statistics

Threads
1,214,985
Messages
6,122,606
Members
449,089
Latest member
Motoracer88

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top