Reply
 
Thread Tools Display Modes
  #1   Report Post  
J Whales
 
Posts: n/a
Default 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   Report Post  
Greg
 
Posts: n/a
Default

You could use REF fields referencing the bookmarked value in the table
cells.

  #3   Report Post  
J Whales
 
Posts: n/a
Default

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   Report Post  
Greg
 
Posts: n/a
Default

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   Report Post  
J Whales
 
Posts: n/a
Default


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

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Table AutoFormats vs. Table Styles confusion Tony Jollans Tables 5 March 6th 05 07:18 PM
Import csv data into a specifically formatted Word table Pat Dools Tables 7 February 28th 05 01:03 PM
Difficulty pasting Excel data into Word table only in XP versions Digitonomy Tables 0 February 28th 05 12:33 AM
Specific Email Merge w/ Specific Attachements Mark B Mailmerge 9 February 21st 05 05:10 AM
How do I insert Excel data as a Word table and stay within margins Fritz Tables 1 February 6th 05 08:39 AM


All times are GMT +1. The time now is 05:24 AM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"