1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Word 2002 - Insert Date of last week.

Discussion in 'Business Applications' started by Slimboy Fat, Jan 26, 2006.

Thread Status:
Not open for further replies.
Advertisement
  1. Slimboy Fat

    Slimboy Fat Thread Starter

    Joined:
    Oct 29, 2004
    Messages:
    156
    Hi,

    Is there a way in word to insert Last Weeks date (i.e. Todays date - 7 days). Would want this to auto update whenever the Document is opened.


    TIA
    Raw2K
     
  2. TonyJollans

    TonyJollans

    Joined:
    Jun 24, 2004
    Messages:
    114
    Yes, there is a way but it is very complex.

    To force it to update whenever the document is opened, however, will require VBA code - and if you're using code anyway it's far easier to calculate the date in VBA than it is in a Word Field.

    Let me know which method you prefer.
     
  3. Slimboy Fat

    Slimboy Fat Thread Starter

    Joined:
    Oct 29, 2004
    Messages:
    156
    Thanks Tony,

    If you think that the VB method will be easier, I will go with that one :)

    Isn't it always the same, the idea seems simple enough (Todays Date - 7 days) but they are always the most complex.
     
  4. bomb #21

    bomb #21

    Joined:
    Jul 1, 2005
    Messages:
    8,546
    OTOH, tis very easy if you have Excel.

    Just create a file (I dunno, "tardy.xls") and stick a formula somewhere: =TODAY()-7

    Then copy this and Paste Special in your doc (unformatted text, paste link).

    When you open the doc, the field will update -- neither the Excel file nor Excel itself need be open. The trade-off is the file takes 5 - 10 secs to open -- then again my RAM is feeble.

    Yet more proof (if any were needed) that Excel trashes Word. :D (OMG, Tony J lives "just down the road" -- who knew? :eek: )
     
  5. TonyJollans

    TonyJollans

    Joined:
    Jun 24, 2004
    Messages:
    114
    Raw2K,

    There are several ways to do this. One of the easiest is to put a DocVariable Field where you want the date to appear ...

    Select Insert > Field from the Menu
    Under Categories, Select "Document Automation"
    Under Field Name, Select "DocVariable"
    Then, in the New Name box, Enter, say, "LastWeek"
    Press OK

    Add this code in the ThisDocument module ...
    Code:
    Private Sub Document_Open()
        ActiveDocument.Variables("LastWeek") = Date - 7
        ActiveDocument.Fields.Update
    End Sub
    Close your Document.
    When you Open it, the Last Week date should be recalculated and displayed in the body of the document.

    bomb #21,

    I'll say nothing about the slur on Word :) - but nowhere is down the road from where we are, so where are you?
     
  6. Anne Troy

    Anne Troy

    Joined:
    Feb 14, 1999
    Messages:
    11,746
    First Name:
    Anne
  7. bomb #21

    bomb #21

    Joined:
    Jul 1, 2005
    Messages:
    8,546
    Western end of the A10, as it happens -- or thereabouts. Sorry to hear about the lack of roads round your way. :D
     
  8. Slimboy Fat

    Slimboy Fat Thread Starter

    Joined:
    Oct 29, 2004
    Messages:
    156
    Sorry, Word noobie here :(

    I've found in the "MyDocument Module" pulldown in the top right corner but how do I add the code.


    Thanks
    Raw2K
     
  9. bomb #21

    bomb #21

    Joined:
    Jul 1, 2005
    Messages:
    8,546
    From the top ...

    1. ALT+F11 takes you to the Visual Basic Editor.

    2. If you don't see the Project Explorer window on the left, press CTRL+R.

    3. Under "Project(YourDoc)", there should be a "Word Objects" folder. Under that there should be "ThisDocument". Doubleclick it & paste the code into the window on the right.
     
  10. Slimboy Fat

    Slimboy Fat Thread Starter

    Joined:
    Oct 29, 2004
    Messages:
    156
    Sorry, I must be daft :(

    I have created a new document the followed Tonys..
    "Select Insert > Field from the Menu
    Under Categories, Select "Document Automation"
    Under Field Name, Select "DocVariable"
    Then, in the New Name box, Enter, say, "LastWeek"
    Press OK"

    I then followed Bombs...
    "1. ALT+F11 takes you to the Visual Basic Editor.

    2. If you don't see the Project Explorer window on the left, press CTRL+R.

    3. Under "Project(YourDoc)", there should be a "Word Objects" folder. Under that there should be "ThisDocument". Doubleclick it & paste the code into the window on the right.
    "

    Closed the document saving it to the desktop. Re-open the document and it displays nothing. Am I missing something here....
     
  11. TonyJollans

    TonyJollans

    Joined:
    Jun 24, 2004
    Messages:
    114
    Sounds correct - can you post your document here so we can take a look?
     
  12. TonyJollans

    TonyJollans

    Joined:
    Jun 24, 2004
    Messages:
    114
    The A10 runs roughly NE from London, doesn't it? So I'm not sure what you mean be western end but could be you're within an hour and a half or so of us which, I suppose, is just down the road - we're near Diss.
     
  13. bomb #21

    bomb #21

    Joined:
    Jul 1, 2005
    Messages:
    8,546
    Oh, that A10. :eek:

    Scratch that then, for "quite a way down the A14 -- near Bar Hill".
     
  14. TonyJollans

    TonyJollans

    Joined:
    Jun 24, 2004
    Messages:
    114
    LOL - OK, so maybe two hours.
     
  15. Sponsor

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/437358

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice