Hi,

What about this code? Why does it return a compile error :"Can't
assign to read only property" word table (wrdTable) ?

wrdTable(ti, tj) = ws.Cells(i, j)

Option Explicit

Sub Send2Word2()

Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False

Dim wb As Workbook
Dim ws As Worksheet
Set wb = ThisWorkbook
Set ws = wb.Worksheets("Feuil")

Dim wrdApp As Word.Application
Dim wrdDoc As Word.Document
Dim wrdTable As Word.Table
Dim wrdRange As Word.Range

Dim xText
Dim i As Integer, j As Integer
Dim ti As Integer, tj As Integer

Set wrdApp = CreateObject("Word.application")
Set wrdDoc = wrdApp.Documents.Add
Set wrdRange = wrdDoc.Range

wrdApp.Visible = True

Set wrdTable = wrdDoc.Tables.Add(Range:=wrdRange, NumRows:=21,
NumColumns:=5)

xText = ws.Range(ws.Cells(4, 2), ws.Cells(22, 5))
With wrdTable
  With .Cell(2, 2).Range
    .InsertAfter xText
  End With

  ti = 1: tj = 2

  For i = 4 To 22
    ti = ti + 1
    For j = 2 To 5
      wrdTable(ti, tj) = ws.Cells(i, j)
      If j < 5 Then
        tj = tj + 1
      Else
        tj = 2
      End If
    Next j
  Next i

End With

Set wrdDoc = Nothing
Set wrdApp = Nothing

Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True

End Sub

Thanks

Johann

-- 
----------------------------------------------------------------------------------
Some important links for excel users:
1. Follow us on TWITTER for tips tricks and links : 
http://twitter.com/exceldailytip
2. Join our LinkedIN group @ http://www.linkedin.com/groups?gid=1871310
3. Excel tutorials at http://www.excel-macros.blogspot.com
4. Learn VBA Macros at http://www.quickvba.blogspot.com
5. Excel Tips and Tricks at http://exceldailytip.blogspot.com
 
To post to this group, send email to excel-macros@googlegroups.com

<><><><><><><><><><><><><><><><><><><><><><>
Like our page on facebook , Just follow below link
http://www.facebook.com/discussexcel

Reply via email to