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

    Home » Forums » AskWoody support » Productivity software by function » MS Word and word processing help » Using data from a table as a field (Word 2002)

    Author
    Topic
    #409606

    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?

    Viewing 3 reply threads
    Author
    Replies
    • #874271

      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.

    • #874272

      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.

    • #874370

      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
      [Fmr MS MVP - Word]

      • #874378

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

        Many thanks.

      • #874379

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

        Many thanks.

    • #874371

      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
      [Fmr MS MVP - Word]

    Viewing 3 reply threads
    Reply To: Reply #874371 in Using data from a table as a field (Word 2002)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information:




    Cancel