PDA

View Full Version : Pasting excel tables one after the other from excel into a word document



reddevil1493
12-14-2016, 08:39 AM
Hi, attached here is a code snippet showing how I've tried to add tables one after the other from excel into a word document; but it doesn't work( the third table defined as "Table2" seems to be pasted instead of the second, defined as "Table 6"), and I also get an error that there are two few arguments. What am I doing incorrectly? Can I use something like .Paragraphs.Last.Range.InsertAfter.PasteExcelTable to ensure that its pasted after the range of the previous one?

With .Paragraphs.Last.Range
.ParagraphFormat.Alignment = wdAlignParagraphLeft
.Font.Size = 14
.Font.Color = RGB(100, 149, 237)
.InsertAfter Worksheets("Description").Range("B2").Value & vbCr & vbCr
End With


'Worksheets("IO").ListObjects("Table6").Range.Copy
'.Paragraphs.Last.Range.PasteExcelTable LinkedToExcel:=True, WordFormatting:=False, RTF:=False


Worksheets("IO").ListObjects("Table6").Range.Copy
.Paragraphs.Last.Range.ParagraphFormat.Alignment = wdAlignParagraphLeft
Worksheets("IO").ListObjects("Table6").Range.Copy
.Paragraphs.Last.Range.PasteExcelTable LinkedToExcel:=True, WordFormatting:=False, RTF:=False




'Clear the clipboard
wdDoc.Styles("Normal").ParagraphFormat.SpaceAfter = 16


Application.CutCopyMode = False
Set wdTbl = .Tables(.Tables.Count)
With wdTbl
.AutoFitBehavior (wdAutoFitWindow)
.Cell(1, 1).SetWidth _
ColumnWidth:=InchesToPoints(1.5), _
RulerStyle:=wdAdjustNone
.Cell(2, 1).SetWidth _
ColumnWidth = InchesToPoints(1.5), _
RulerStyle:=wdAdjustNone

With .Range.Font
.Name = "Arial"
.Size = 14
.Color = RGB(100, 149, 237)
End With
End With




'Copy excel range of table for Investor Profile
Worksheets("Inv Profile").ListObjects("Table2").Range.Copy
.Paragraphs.Last.Range.InsertAfter.PasteExcelTable LinkedToExcel:=True, WordFormatting:=False, RTF:=False

'clear the clipboard
' wdDoc.Styles("Normal").ParagraphFormat.SpaceAfter = 16
' Application.CutCopyMode = False



'Set wdTbl = .Tables(.Tables.Count)
'With wdTbl
' .AutoFitBehavior (wdAutoFitWindow)
' .Cell(1, 1).SetWidth _
' ColumnWidth:=InchesToPoints(1.5), _
' RulerStyle:=wdAdjustNone
'.Cell(2, 1).SetWidth _
' ColumnWidth = InchesToPoints(1.5), _
' RulerStyle:=wdAdjustNone

' With .Range.Font
' .Name = "Arial"
' .Size = 14
' .Color = RGB(100, 149, 237)
' End With
'End With


' Copy excel range of table for Portfolio Characteristics
'Worksheets("Port Char").ListObjects("Table3").Range.Copy
'.Paragraphs.Last.Range.PasteExcelTable LinkedToExcel:=True, WordFormatting:=False, RTF:=False

'clear the clipboard
'wdDoc.Styles("Normal").ParagraphFormat.SpaceAfter = 16
'Application.CutCopyMode = False



'Set wdTbl = .Tables(.Tables.Count)
'With wdTbl
' .AutoFitBehavior (wdAutoFitWindow)
' .Cell(1, 1).SetWidth _
' ColumnWidth:=InchesToPoints(1.5), _
' RulerStyle:=wdAdjustNone
'.Cell(2, 1).SetWidth _
' ColumnWidth = InchesToPoints(1.5), _
' RulerStyle:=wdAdjustNone

' With .Range.Font
' .Name = "Arial"
' .Size = 14
' .Color = RGB(100, 149, 237)
' End With
'End With
End With