Hi all,
I use the following piece of code to copy a bunch of named tables in my Excel-file to a Word document.
The tables are named "Question1" etc which are located on a sheet called "Tables". myDoc is an opened Word document
From time to time the script stops and returns an Error 5941 with the statement "Method Item of object Paragraph failed" (Could be a bit different because I use a Dutch version and this is the litteral translation).
The script stops at the instruction in red above.
The behaviour is random. Sometimes it stops at i =10 or so, sometimes at i = 4 and sometimes it completes all the way until NumberOfQuestions. When it fails and I just retry it may work or stop at another i.
Any ideas?
I use the following piece of code to copy a bunch of named tables in my Excel-file to a Word document.
The tables are named "Question1" etc which are located on a sheet called "Tables". myDoc is an opened Word document
Code:
For i = 1 To NumberOfQuestions
iParCount = myDoc.Paragraphs.Count
TableName = "Question" & i
Set tbl = ThisWorkbook.Worksheets("Tables").ListObjects(TableName).Range
tbl.Copy
[COLOR=#ff0000] myDoc.Paragraphs(iParCount).Range.PasteExcelTable _[/COLOR]
[COLOR=#ff0000] LinkedToExcel:=False, _[/COLOR]
[COLOR=#ff0000] WordFormatting:=False, _[/COLOR]
[COLOR=#ff0000] RTF:=True[/COLOR]
myDoc.Paragraphs.Add
Next i
From time to time the script stops and returns an Error 5941 with the statement "Method Item of object Paragraph failed" (Could be a bit different because I use a Dutch version and this is the litteral translation).
The script stops at the instruction in red above.
The behaviour is random. Sometimes it stops at i =10 or so, sometimes at i = 4 and sometimes it completes all the way until NumberOfQuestions. When it fails and I just retry it may work or stop at another i.
Any ideas?