N
NYSA-HD
I am running the following code to insert a table into a document. My
problem is that every so often the table inserts strangely and runs off the
page. I have chalked it up to a word bug, but it is getting annoying. Has
anyone else had this problem when inserting tables using code. Is there
anything I can change below that might eliminate this seemly random problem.
Is there a line of code that will correct this issue?
------------------------------
Public Sub InsertVotes()
If FindVar("&VOTES") Then Selection.Delete unit:=wdCharacter, Count:=1
If (pubYEAS <> "" And pubYEAS <> "00") Or (pubNAYS <> "" And pubNAYS <>
"00") Then
InsertVoteBox
Else
' Do nothing if no vote taken
Selection.Delete unit:=wdCharacter, Count:=1
End If
End Sub
Public Sub InsertVoteBox()
Selection.TypeParagraph
ActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=2,
NumColumns:= _
2, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:= _
wdAutoFitFixed
With Selection.Tables(1)
.PreferredWidthType = wdPreferredWidthPoints
.PreferredWidth = InchesToPoints(0.67)
.Columns(1).PreferredWidth = InchesToPoints(0.42)
.Columns(2).PreferredWidth = InchesToPoints(0.25)
.Rows.SetLeftIndent LeftIndent:=InchesToPoints(3),
RulerStyle:=wdAdjustNone
If .Style <> "Table Grid" Then
.Style = "Table Grid"
End If
.ApplyStyleHeadingRows = True
.ApplyStyleLastRow = True
.ApplyStyleFirstColumn = True
.ApplyStyleLastColumn = True
.Borders(wdBorderLeft).LineStyle = wdLineStyleNone
.Borders(wdBorderRight).LineStyle = wdLineStyleNone
.Borders(wdBorderTop).LineStyle = wdLineStyleNone
.Borders(wdBorderBottom).LineStyle = wdLineStyleNone
.Borders(wdBorderHorizontal).LineStyle = wdLineStyleNone
.Borders(wdBorderVertical).LineStyle = wdLineStyleNone
.Borders(wdBorderDiagonalDown).LineStyle = wdLineStyleNone
.Borders(wdBorderDiagonalUp).LineStyle = wdLineStyleNone
.Borders.Shadow = False
' Added these characteristics: 7/26/06
.TopPadding = InchesToPoints(0)
.BottomPadding = InchesToPoints(0)
.LeftPadding = InchesToPoints(0)
.RightPadding = InchesToPoints(0)
End With
Selection.TypeText Text:="YEAS"
Selection.MoveRight unit:=wdCell
Selection.TypeText Text:=pubYEAS
Selection.ParagraphFormat.Alignment = wdAlignParagraphRight
Selection.MoveRight unit:=wdCell
Selection.TypeText Text:="NAYS"
Selection.MoveRight unit:=wdCell
Selection.TypeText Text:=pubNAYS
Selection.ParagraphFormat.Alignment = wdAlignParagraphRight
Selection.MoveRight unit:=wdCharacter, Count:=2
End Sub
problem is that every so often the table inserts strangely and runs off the
page. I have chalked it up to a word bug, but it is getting annoying. Has
anyone else had this problem when inserting tables using code. Is there
anything I can change below that might eliminate this seemly random problem.
Is there a line of code that will correct this issue?
------------------------------
Public Sub InsertVotes()
If FindVar("&VOTES") Then Selection.Delete unit:=wdCharacter, Count:=1
If (pubYEAS <> "" And pubYEAS <> "00") Or (pubNAYS <> "" And pubNAYS <>
"00") Then
InsertVoteBox
Else
' Do nothing if no vote taken
Selection.Delete unit:=wdCharacter, Count:=1
End If
End Sub
Public Sub InsertVoteBox()
Selection.TypeParagraph
ActiveDocument.Tables.Add Range:=Selection.Range, NumRows:=2,
NumColumns:= _
2, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:= _
wdAutoFitFixed
With Selection.Tables(1)
.PreferredWidthType = wdPreferredWidthPoints
.PreferredWidth = InchesToPoints(0.67)
.Columns(1).PreferredWidth = InchesToPoints(0.42)
.Columns(2).PreferredWidth = InchesToPoints(0.25)
.Rows.SetLeftIndent LeftIndent:=InchesToPoints(3),
RulerStyle:=wdAdjustNone
If .Style <> "Table Grid" Then
.Style = "Table Grid"
End If
.ApplyStyleHeadingRows = True
.ApplyStyleLastRow = True
.ApplyStyleFirstColumn = True
.ApplyStyleLastColumn = True
.Borders(wdBorderLeft).LineStyle = wdLineStyleNone
.Borders(wdBorderRight).LineStyle = wdLineStyleNone
.Borders(wdBorderTop).LineStyle = wdLineStyleNone
.Borders(wdBorderBottom).LineStyle = wdLineStyleNone
.Borders(wdBorderHorizontal).LineStyle = wdLineStyleNone
.Borders(wdBorderVertical).LineStyle = wdLineStyleNone
.Borders(wdBorderDiagonalDown).LineStyle = wdLineStyleNone
.Borders(wdBorderDiagonalUp).LineStyle = wdLineStyleNone
.Borders.Shadow = False
' Added these characteristics: 7/26/06
.TopPadding = InchesToPoints(0)
.BottomPadding = InchesToPoints(0)
.LeftPadding = InchesToPoints(0)
.RightPadding = InchesToPoints(0)
End With
Selection.TypeText Text:="YEAS"
Selection.MoveRight unit:=wdCell
Selection.TypeText Text:=pubYEAS
Selection.ParagraphFormat.Alignment = wdAlignParagraphRight
Selection.MoveRight unit:=wdCell
Selection.TypeText Text:="NAYS"
Selection.MoveRight unit:=wdCell
Selection.TypeText Text:=pubNAYS
Selection.ParagraphFormat.Alignment = wdAlignParagraphRight
Selection.MoveRight unit:=wdCharacter, Count:=2
End Sub