I am using the ConvertToTable method in Word VBA to convert a tab and carriage return delimited text string into a table. This works very well, except when I have a lot of rows of data in the string to convert. When there is a lot of text and the table should continue on the next page the method breaks. Instead of wrapping the table to the next page or stopping with an abridged table on the original page, the table is either created and not displayed or not created at all. Has anyone got an idea on what could be happening here and how to fix it?
Here is the section of the script that is using the .ConvertToTable method.
'-----------------------
With Selection
.InsertAfter CTL
Set objTable = .ConvertToTable (Separator:=wdSeparateByTabs, AutoFit:=True, defaulttablebehavior:=wdWord9TableBehavior)
DoEvents
With objTable
.Range.ParagraphFormat.Alignment = wdAlignParagraphLeft
.Range.Cells.VerticalAlignment = wdCellAlignVerticalCenter
.Columns(3).PreferredWidth = InchesToPoints(1.8)
.Columns(2).PreferredWidth = InchesToPoints(2.8)
.Columns(1).PreferredWidth = InchesToPoints(3.1)
.Rows.Add(.Rows(1)).HeadingFormat = True
.Rows.Add(.Rows(1)).HeadingFormat = True
.Rows(1).Cells.Merge
With .Cell(1, 1).Range
.Font.Bold = True
.Text = "CONTACT NUMBERS (In Case of Emergency):"
End With
.Rows(2).Range.Font.Bold = True
.Cell(2, 1).Range.Text = "AGENCY NAME / TITLE"
.Cell(2, 2).Range.Text = "NAME"
.Cell(2, 3).Range.Text = "PHONE NUMBER"
End With
DoEvents
End With
'-------------------------------------
Here is the section of the script that is using the .ConvertToTable method.
'-----------------------
With Selection
.InsertAfter CTL
Set objTable = .ConvertToTable (Separator:=wdSeparateByTabs, AutoFit:=True, defaulttablebehavior:=wdWord9TableBehavior)
DoEvents
With objTable
.Range.ParagraphFormat.Alignment = wdAlignParagraphLeft
.Range.Cells.VerticalAlignment = wdCellAlignVerticalCenter
.Columns(3).PreferredWidth = InchesToPoints(1.8)
.Columns(2).PreferredWidth = InchesToPoints(2.8)
.Columns(1).PreferredWidth = InchesToPoints(3.1)
.Rows.Add(.Rows(1)).HeadingFormat = True
.Rows.Add(.Rows(1)).HeadingFormat = True
.Rows(1).Cells.Merge
With .Cell(1, 1).Range
.Font.Bold = True
.Text = "CONTACT NUMBERS (In Case of Emergency):"
End With
.Rows(2).Range.Font.Bold = True
.Cell(2, 1).Range.Text = "AGENCY NAME / TITLE"
.Cell(2, 2).Range.Text = "NAME"
.Cell(2, 3).Range.Text = "PHONE NUMBER"
End With
DoEvents
End With
'-------------------------------------