gpalmer711
IS-IT--Management
Hi,
I have a wierd issue with tables when using word automation in vb.net.
I have the following code
I am expecting this to create two separate tables, each with 5 rows - however it creates a single table with 10 rows.
Could someone point me in the right direction?
Greg Palmer
Freeware Utilities for Windows Administrators.
I have a wierd issue with tables when using word automation in vb.net.
I have the following code
Code:
Imports word = Microsoft.Office.Interop.Word
Public Class frmMain
Private Sub cmdSettings_Click(sender As Object, e As EventArgs) Handles cmdSettings.Click
frmSettings.Show(Me)
End Sub
Private Sub cmdGenerate_Click(sender As Object, e As EventArgs) Handles cmdGenerate.Click
Dim objApp = New word.Application
Dim objDoc = New word.Document
objApp.Visible = True
objDoc = objApp.Documents.Add()
objDoc.Activate()
objDoc.PageSetup.PageWidth = 294.8
objDoc.PageSetup.PageHeight = 405.35
objDoc.PageSetup.RightMargin = 25.5
objDoc.PageSetup.LeftMargin = 25.5
objDoc.PageSetup.TopMargin = 25.5
objDoc.PageSetup.BottomMargin = 28.4
generateLeftPageTable(objDoc.Bookmarks.Item("\endofdoc").Range)
generateLeftPageTable(objDoc.Bookmarks.Item("\endofdoc").Range)
End Sub
Public Sub generateLeftPageTable(objRange As word.Range)
Dim objTable As word.Table
objTable = objRange.Tables.Add(objRange, 5, 1)
objTable.Borders.Enable = True
objTable.Borders.OutsideLineStyle = word.WdLineStyle.wdLineStyleNone
objTable.Borders.InsideLineStyle = word.WdLineStyle.wdLineStyleSingle
For intRow = 1 To 5
If intRow = 1 Then
objTable.Cell(intRow, 1).SetHeight(17, word.WdRowHeightRule.wdRowHeightExactly)
objTable.Cell(intRow, 1).BottomPadding = 0
objTable.Cell(intRow, 1).TopPadding = 0
objTable.Cell(intRow, 1).LeftPadding = 0
objTable.Cell(intRow, 1).RightPadding = 0
objTable.Cell(intRow, 1).Borders(word.WdBorderType.wdBorderBottom).LineStyle = word.WdLineStyle.wdLineStyleSingle
objTable.Cell(intRow, 1).Shading.BackgroundPatternColor = word.WdColor.wdColorBlack
objTable.Cell(intRow, 1).Range.Text = "Row " & intRow
Else
objTable.Cell(intRow, 1).SetHeight(82.2, word.WdRowHeightRule.wdRowHeightExactly)
objTable.Cell(intRow, 1).BottomPadding = 0
objTable.Cell(intRow, 1).TopPadding = 0
objTable.Cell(intRow, 1).LeftPadding = 0
objTable.Cell(intRow, 1).RightPadding = 0
objTable.Cell(intRow, 1).Borders(word.WdBorderType.wdBorderBottom).LineStyle = word.WdLineStyle.wdLineStyleSingle
objTable.Cell(intRow, 1).Range.Text = "Row " & intRow
End If
Next
objTable = Nothing
End Sub
End Class
I am expecting this to create two separate tables, each with 5 rows - however it creates a single table with 10 rows.
Could someone point me in the right direction?
Greg Palmer
Freeware Utilities for Windows Administrators.