ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Create a Word Table from a Excel Macro (https://www.excelbanter.com/excel-discussion-misc-queries/108799-create-word-table-excel-macro.html)

Silvia

Create a Word Table from a Excel Macro
 
Hello Everybody

I'm really new at using macros (a week or so..) and i am having a few
problems creating word tables.
What i want to do is : create a word document, copy text from a cell
in a excel worksheet into a paragraph in the word document and then
copy other cells into a table in the word document.

The table is created just fine, but when i try to insert more text
outside the table i wont let me.
Everything is inserted into the first cell of my word table...

Any idea why is this happening? =(

Thanks in advance!




Sub CreateNewTable()
Dim docActive As Document
Dim tblNew As Table
Dim celTable As Cell
Dim intCount As Integer

'Create word document
Set docActive = CreateObject("Word.Document")

'Create word table
Set tblNew = docActive.Tables.Add( _
Range:=docActive.Range(Start:=0, End:=0), NumRows:=3, _
NumColumns:=4)
intCount = 1

'Fill the cells in the table
For Each celTable In tblNew.Range.Cells
celTable.Range.InsertAfter "Cell " & intCount 'or the
..values from my excel..
intCount = intCount + 1
Next celTable

tblNew.AutoFormat ApplyBorders:=True, ApplyFont:=True,
ApplyColor:=True


'I want this followint text to be a new paragraph after the table
but instead it is inserted inside the Table =(

With docActive.ActiveWindow.Selection

.TypeParagraph
.Font.Name = "Arial"
.Font.Size = "22"
.Font.Color = RGB(64, 128, 192)
.TypeText Text:="Cell Comments In Workbook: " + ActiveWorkbook.Name
.TypeParagraph

End With

End Sub



All times are GMT +1. The time now is 08:35 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com