A
Alex St-Pierre
Hi !
I create a report in Word using Excel VBA. All Excel tables are copied into
Word and then formatted. The report is about 25 pages and countains 20
tables. If I execute the first part (about 10 tables) or the last part (about
10 tables), it works well. If I execute all the report, the report stop at
the following line (around table #16). Any idea?
Example #1 (executed from Excel):
Dim oXlRng As Range
Dim appWord As Word.Application
Dim docWord As Word.Document
Dim oRange As Word.Range
Set appWord = New Word.Application
appWord.Visible = True
Set docWord = appWord.Documents.Add
Set oXlRng = ThisWorkbook.Sheets(T(iTab).SheetName).Range("TableOutput")
....
ThisWorkbook.Activate
oXlRng.Copy
docWord.Activate
iP = docWord.Paragraphs.Count
Set oRange = docWord.Paragraphs(iP).Range
oRange.PasteExcelTable LinkedToExcel:=False, WordFormatting:=False,
RTF:=False 'This returns an error 4198 and the table is not copied. ???
'If I try to re-execute the line, it still gives the same error..
Example #2 (An other example that happens only when I put the 20 tables
together is the following):
iP = DocWord.Paragraphs.Count
Set oRange = docWord.Paragraphs(iP).Range
oRange.InsertAfter "MyText"
oRange.Borders(wdBorderTop).LineStyle = wdLineStyleSingle
oRange.Borders(wdBorderTop).LineWidth = wdLineWidth050pt 'Gives error
5843 outside limit since there's no line..?
oRange.Borders.DistanceFromTop = 4
Thanks!
Alex
I create a report in Word using Excel VBA. All Excel tables are copied into
Word and then formatted. The report is about 25 pages and countains 20
tables. If I execute the first part (about 10 tables) or the last part (about
10 tables), it works well. If I execute all the report, the report stop at
the following line (around table #16). Any idea?
Example #1 (executed from Excel):
Dim oXlRng As Range
Dim appWord As Word.Application
Dim docWord As Word.Document
Dim oRange As Word.Range
Set appWord = New Word.Application
appWord.Visible = True
Set docWord = appWord.Documents.Add
Set oXlRng = ThisWorkbook.Sheets(T(iTab).SheetName).Range("TableOutput")
....
ThisWorkbook.Activate
oXlRng.Copy
docWord.Activate
iP = docWord.Paragraphs.Count
Set oRange = docWord.Paragraphs(iP).Range
oRange.PasteExcelTable LinkedToExcel:=False, WordFormatting:=False,
RTF:=False 'This returns an error 4198 and the table is not copied. ???
'If I try to re-execute the line, it still gives the same error..
Example #2 (An other example that happens only when I put the 20 tables
together is the following):
iP = DocWord.Paragraphs.Count
Set oRange = docWord.Paragraphs(iP).Range
oRange.InsertAfter "MyText"
oRange.Borders(wdBorderTop).LineStyle = wdLineStyleSingle
oRange.Borders(wdBorderTop).LineWidth = wdLineWidth050pt 'Gives error
5843 outside limit since there's no line..?
oRange.Borders.DistanceFromTop = 4
Thanks!
Alex