Home |
Search |
Today's Posts |
#1
|
|||
|
|||
Get data from the last row of a table
Hi!
In our documents we have a Version History table that lists all the revisions for the current document (how, what, when...). On the document's cover page, I would like to display some information from the LAST row of the version history table. Is there a way to that? I looked at fields, but what I found was mostly for calculation... Thanks to anyone that can help. J Whales |
#2
|
|||
|
|||
You could use REF fields referencing the bookmarked value in the table
cells. |
#3
|
|||
|
|||
J Whales wrote:
In our documents we have a Version History table that lists all the revisions for the current document (how, what, when...). On the document's cover page, I would like to display some information from the LAST row of the version history table. Is there a way to that? I looked at fields, but what I found was mostly for calculation... Greg wrote: You could use REF fields referencing the bookmarked value in the table cells. Yeah, but I would prefer not to rely on the user having to add a bookmark whenever they add something in the table. I already have enough difficulties having them use the proper styles... |
#4
|
|||
|
|||
Ok, you could use a macro to set docVariables to the value of the
table cells in the last row and then use DocVariable fields on page 1. Sub ScratchMacro() Dim oTable As Table Dim oDoc As Document Dim txtWho As String Dim txtWhat As String Dim txtWhere As String Dim txtWhen As String Dim txtWhy As String Dim i As Integer Set oDoc = ActiveDocument Set oTable = oDoc.Tables(1) i = oTable.Rows.Count txtWho = oTable.Cell(i, 1).Range.Text txtWho = Left(txtWho, Len(txtWho) - 2) txtWhat = oTable.Cell(i, 2).Range.Text txtWhat = Left(txtWhat, Len(txtWhat) - 2) txtWhere = oTable.Cell(i, 3).Range.Text txtWhere = Left(txtWhere, Len(txtWhere) - 2) txtWhen = oTable.Cell(i, 4).Range.Text txtWhen = Left(txtWhen, Len(txtWhen) - 2) txtWhy = oTable.Cell(i, 5).Range.Text txtWhy = Left(txtWhy, Len(txtWhy) - 2) oDoc.Variables("Who").Value = txtWho oDoc.Variables("What").Value = txtWhat oDoc.Variables("Where").Value = txtWhere oDoc.Variables("When").Value = txtWhen oDoc.Variables("Why").Value = txtWhy ActiveDocument.Fields.Update End Sub |
#5
|
|||
|
|||
Greg wrote: Ok, you could use a macro to set docVariables to the value of the table cells in the last row and then use DocVariable fields on page 1. Sub ScratchMacro() Dim oTable As Table Dim oDoc As Document Dim txtWho As String Dim txtWhat As String Dim txtWhere As String Dim txtWhen As String Dim txtWhy As String Dim i As Integer Set oDoc = ActiveDocument Set oTable = oDoc.Tables(1) i = oTable.Rows.Count txtWho = oTable.Cell(i, 1).Range.Text txtWho = Left(txtWho, Len(txtWho) - 2) txtWhat = oTable.Cell(i, 2).Range.Text txtWhat = Left(txtWhat, Len(txtWhat) - 2) txtWhere = oTable.Cell(i, 3).Range.Text txtWhere = Left(txtWhere, Len(txtWhere) - 2) txtWhen = oTable.Cell(i, 4).Range.Text txtWhen = Left(txtWhen, Len(txtWhen) - 2) txtWhy = oTable.Cell(i, 5).Range.Text txtWhy = Left(txtWhy, Len(txtWhy) - 2) oDoc.Variables("Who").Value = txtWho oDoc.Variables("What").Value = txtWhat oDoc.Variables("Where").Value = txtWhere oDoc.Variables("When").Value = txtWhen oDoc.Variables("Why").Value = txtWhy ActiveDocument.Fields.Update End Sub Thanks Greg! I had something like that in mind; I was hoping there would be something more 'automatic'. Again, thanks for your help |
Reply |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Table AutoFormats vs. Table Styles confusion | Tables | |||
Import csv data into a specifically formatted Word table | Tables | |||
Difficulty pasting Excel data into Word table only in XP versions | Tables | |||
Specific Email Merge w/ Specific Attachements | Mailmerge | |||
How do I insert Excel data as a Word table and stay within margins | Tables |