Results 1 to 8 of 8
  1. #1
    New Lounger
    Join Date
    Aug 2002
    Location
    Chicago, USA
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Calculated dates in Word (Word 2000)

    Hi everyone.
    I am looking for help with calculated dates, but not the Current date plus X days.
    Instead of the current date is there a way to have defined a one field (A) into which I will enter a date and another field ([img]/forums/images/smilies/cool.gif[/img] which will then display the calculated one.
    Also, I need to be able to manually enter the number of the days I need to add (perhaps a input box of some kind) to the (A) date.
    I had some VB experience in the past, but do not consider myself to proficient.
    Any help will be greatly appreciated.
    Toms

  2. #2
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Sunrise, Florida
    Posts
    324
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Calculated dates in Word (Word 2000)

    Want to try this?
    -------------------------------------
    Sub test()
    '
    Dim Message As String
    Dim Title As String
    Dim DefaultDays As Integer
    Dim DaysToAdd As Integer
    Dim PresentDate As Date
    Dim FutureDate As Date

    'Collect date entered (assumes cursor is at end of date)

    Selection.HomeKey Unit:=wdLine, Extend:=wdExtend

    PresentDate = Selection

    ' Set parameters for Message Box that will ask user for
    ' the number of days to be added to Today's Date

    Message = "Enter number of days to add to Today's Date" & vbLf & _
    "(Suggest multiple of 7)" & vbLf & "Default is 21" ' Set prompt.

    Title = "GET DATE IN THE FUTURE" ' Set title.

    DefaultDays = "21" ' Set default.

    ' Display Message Box and get number of follow-up days

    DaysToAdd = InputBox(Message, Title, DefaultDays)

    FutureDate = PresentDate + DaysToAdd

    'Move one cell to the right
    Selection.MoveRight Unit:=wdCell

    Selection.TypeText FutureDate

    End Sub

  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: Calculated dates in Word (Word 2000)

    Hi Toms,
    How about a non-macro solution, using a Word field (attached).
    Cheers
    Attached Files Attached Files
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  4. #4
    New Lounger
    Join Date
    Aug 2002
    Location
    Chicago, USA
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Calculated dates in Word (Word 2000)

    Thanks for quick reply.
    I don't know if I did it correctly or not.. I created the Text Form Field with bookmark name as PresentDate and another Text Form Field with bookmark name as FutureDate and then added to the last one yours "Test " macro in the "Run macro on Entry". I protected the document and entered the PresentDate in proper field, but after I clicked on the FutureDate field I get an error "Type Mismatch".
    Any idea, what I did wrong.

  5. #5
    New Lounger
    Join Date
    Aug 2002
    Location
    Chicago, USA
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Calculated dates in Word (Word 2000)

    Hi, Looks good too, but how do I use it in the document. Can it be used in the Word forms?
    I need to protect the documet and allow user only to fill in blanks.
    The input and output dates are in different places, separated by two lines and some text.
    Thanks

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

    Re: Calculated dates in Word (Word 2000)

    Hi Toms,

    Yes, the field solution can be used in a document protected for forms.

    Regarding the input and output dates being in different places, there's at least two ways you could deal with this. One way is to put all of the intervening text & paras into the field itself. The solution I posted previously is an example of this, though I didn't insert any paragraphs. Another is to put each ASK statement and an associated QUOTE/BOOKMARK combination where you want it. The attached update has an example of this also.

    Cheers

    PS: All of the line feeds in the fields are superfluous and are used only to aid clarity.

    PPS: OK, so maybe 'clarity' is a bit of an overstatement ...
    Attached Files Attached Files
    Cheers,

    Paul Edstein
    [MS MVP - Word]

  7. #7
    New Lounger
    Join Date
    Aug 2002
    Location
    Chicago, USA
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Calculated dates in Word (Word 2000)

    Macropod,
    thanks so much I got it working. The only thing I need to do is to change the way starting date is displayed (e.g.10-Feb-2003).
    Toms

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

    Re: Calculated dates in Word (Word 2000)

    <P ID="edit" class=small>(Edited by macropod on 10-Feb-03 07:43. Correction to advice on how to force Statedate field to display correctly.)</P>Hi Toms,

    That's easy: Change the last line in the field to {ReplyDay}"-"{ReplyMonth @ "MMM"}"-"{ReplyYear}"."} or {ReplyDay}"-"{ReplyMonth @ "MMM"}"-"{ReplyYear}} , depending on which version of the solution you're using.

    Note: The way the starting date is displayed isn't affected by this change - only the final calculated date is affected. If you need to trap different input date formats and ensure they are displayed correctly, that would require the {Startdate} field to be changed to {Startdate @ "d-MMM-yyyy"} .

    Cheers
    Cheers,

    Paul Edstein
    [MS MVP - Word]

Posting Permissions

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