Hi!
When I try to add new rows to an existing table(with data) the previous filled in data disappear.
Private Sub cmdInsertTable_Click()
With PDFcreator
' create a table object
.CreateObject acObjectTypeTable, "Table 1"
' position the table object
.ObjectAttribute("Table 1", "Left") = 100
.ObjectAttribute("Table 1", "Top") = 1000
.ObjectAttribute("Table 1", "Right") = 3600
.ObjectAttribute("Table 1", "Bottom") = 2800
.ObjectAttribute("Table 1", "Rows") = 2
.ObjectAttribute("Table 1", "Columns") = 2
.ObjectAttribute("Table 1.Cells[1,1]", "Text") = "Text 1,1"
.ObjectAttribute("Table 1.Cells[1,2]", "Text") = "Text 1,2"
.ObjectAttribute("Table 1.Cells[2,1]", "Text") = "Text 2,1"
.ObjectAttribute("Table 1.Cells[2,2]", "Text") = "Text 2,2"
' Add a new row
.PDF1.ObjectAttribute("Table 1", "Rows") = .PDF1.ObjectAttribute("Table 1", "Rows") + 1
End With
End Sub
Adding new rows
Hello,
There are a couple of methods available that will allow you to add rows to a table. The method you have described will re-initialize the table.
If you wish to add a row and keep the existing table data please us the code snippet below:
Private Sub cmdAddRow_Click()
Dim intRows As Integer
Dim intRowWidth As Integer
With PDF1
'Open PDF document which includes the table object that you
'want to add rows to.
.Open App.Path & "\sample.pdf", ""
'Put the Documetn into design mode
.DoCommandTool (acCommandToolDesignMode)
'Active the object
.ActivateObject "Table 1"
'Find number of rows in the opened document
intRows = .ObjectAttribute("Table 1", "Rows")
'Get width of Table object
intRowWidth = (.ObjectAttribute("Table 1", "Bottom")) - _
(.ObjectAttribute("Table 1", "Top"))
'Insert new row into Table
.DoCommandTool (acCommandToolInsertRow)
'Inlarge Table in order to add ne row
' Table Bottom = Table width / number of rows
.ObjectAttribute("Table 1", "Bottom") = CInt(intRowWidth / intRows) + _
CInt(.ObjectAttribute("Table 1", "Bottom"))
'Compile new document
.DoCommandTool (acCommandToolRunDocument)
.Refresh
.Save App.Path & "\sample_revised.pdf", 0
End With
End Sub
Thanks
There are a couple of methods available that will allow you to add rows to a table. The method you have described will re-initialize the table.
If you wish to add a row and keep the existing table data please us the code snippet below:
Private Sub cmdAddRow_Click()
Dim intRows As Integer
Dim intRowWidth As Integer
With PDF1
'Open PDF document which includes the table object that you
'want to add rows to.
.Open App.Path & "\sample.pdf", ""
'Put the Documetn into design mode
.DoCommandTool (acCommandToolDesignMode)
'Active the object
.ActivateObject "Table 1"
'Find number of rows in the opened document
intRows = .ObjectAttribute("Table 1", "Rows")
'Get width of Table object
intRowWidth = (.ObjectAttribute("Table 1", "Bottom")) - _
(.ObjectAttribute("Table 1", "Top"))
'Insert new row into Table
.DoCommandTool (acCommandToolInsertRow)
'Inlarge Table in order to add ne row
' Table Bottom = Table width / number of rows
.ObjectAttribute("Table 1", "Bottom") = CInt(intRowWidth / intRows) + _
CInt(.ObjectAttribute("Table 1", "Bottom"))
'Compile new document
.DoCommandTool (acCommandToolRunDocument)
.Refresh
.Save App.Path & "\sample_revised.pdf", 0
End With
End Sub
Thanks