Results 1 to 4 of 4
  1. #1
    Star Lounger
    Join Date
    Mar 2002
    Location
    San Jose, California, USA
    Posts
    82
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Using data from a table as a field (Word 2002)

    A number of our documents are created with a "revision history" table. The front page and page headers carry the latest revision number. Every time the document is revised the current revision number has to be entered in at least 3 places. I am wondering if it's not possible to create a simple macro to look down the "Rev" column in the revision history table, and assign the highest value found to a user field that could be inserted into the page headers and front page titles.

    Is that something that's feasible in Word?

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Using data from a table as a field (Word 2002)

    Word offers two handy repositories for information to be displayed in various places: Document Properties (File>Properties...>Custom) and Document Variables (no user interface to view or edit). The corresponding field codes are DOCPROPERTY (Insert>Field...>Document Information) and DOCVARIABLE (Insert>Field...>Document Automation). If you search around here and on the VB/VBA board, you can get some "pro and con" on these two choices. Either would work for displaying the value in your document.

    As for the macro, hopefully someone can help with code to find a high value. I can think of some ways, but they probably are not the most efficient ways.

    Then you have to decide what will trigger the macro. For example, should it run the first time the user saves the document during that session of Word? When the document is printed? Closed? Or when the user clicks a button? Each involves different coding, some more complicated than others.

  3. #3
    Super Moderator
    Join Date
    May 2002
    Location
    Canberra, Australian Capital Territory, Australia
    Posts
    5,054
    Thanks
    2
    Thanked 417 Times in 346 Posts

    Re: Using data from a table as a field (Word 2002)

    Hi Keith,

    Perhaps the easiest way to do this is to bookmark the table (eg RevTbl), then use a simple formula field to find the maximum value. For example, if the revisions are listed in column C, you could obtain the 'highest' number with:
    {=MAX(RevTbl C:C)}
    To create such a field after bookmarking the table, press Ctrl-F9 to create a pair of field braces '{ }' then type the formula between them and press F9 to update. Simply replicate the field wherever you want this number to appear.

    As described, the field will return whole numbers or decimals, but whole numbers won't have any trailing decimal places. If you always want, say two, decimal places, code the field as:
    {=MAX(RevTbl C:C) # 0.00}

    If you need to add rows to the table, select the lower right cell and press the tab key. Alternatively, use Table|Insert|Rows. Either method will extend the bookmark to include the new row, whereas copying and pasting an earlier row below the last row won't

    The only other thing to bear in mind is that any text in the same cells will be dropped and if you have more than one number in the same cell, Word will add them together.

    Whenever the revision number is updated, you can update all references to it by selecting the whole document and pressing F9 (which updates all fields in the document). Alternatively, if you've got 'update fields' checked under Tools|Options|Print, the fields will update of their own accord at print time.

    Cheers
    PS: No macros required!
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  4. #4
    Star Lounger
    Join Date
    Mar 2002
    Location
    San Jose, California, USA
    Posts
    82
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Re: Using data from a table as a field (Word 2002)

    Very Slick! Works like a dream - and no macros!

    Many thanks.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •