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

    Lost code when template is shared (Word 2K)

    I have a template that executes a macro when the user tabs out of a cell. It works all right in my PC. I've sent copies of my template to other users but when they try to get the same results, neither the macro nor the instruction on the cell's "on exit" is there! What could be wrong? Thanks in advance for the assistance!!!

    Solved the problem. Thanks anyway!!!!

  2. #2
    5 Star Lounger
    Join Date
    Jul 2002
    Location
    Toronto, Ontario, Canada
    Posts
    1,139
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Lost code when template is shared (Word 2K)

    What was the solution so that others may benefit from it as well?
    --
    Bryan Carbonnell - Toronto <img src=/S/flags/Ontario.gif border=0 alt=Ontario width=30 height=18> <img src=/S/flags/Canada.gif border=0 alt=Canada width=30 height=18>
    Unfortunately common sense isn't so common!!
    Visit my website for useful Word, Excel and Access code, templates and Add-Ins

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

    Re: Lost code when template is shared (Word 2K)

    Sorry. Here is "my" solution.

    The document contains a table with form elements; mostly text cells, and is protected for forms. I Wrote the following macro:
    ------------------------------
    Sub Age()
    '
    Dim DateSelected As Date
    Dim TestOne As Date
    Dim TestTwo As Date
    Dim AttainedAge As Integer
    ActiveDocument.Unprotect
    Selection.HomeKey Unit:=wdLine, Extend:=wdExtend
    If IsDate(Selection.Text) Then
    DateSelected = Selection.Text
    AttainedAge = DateDiff("yyyy", DateSelected, Date)
    TestOne = Date
    TestTwo = Month(DateSelected) & "/" & Day(DateSelected) & "/" & Year(Date)
    If TestTwo > TestOne Then
    AttainedAge = AttainedAge - 1
    End If
    Selection.MoveRight Unit:=wdCell, Count:=2
    Selection.Text = AttainedAge
    ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
    Else
    Selection.MoveRight Unit:=wdCell, Count:=4
    ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
    Exit Sub
    End If
    End Sub
    ------------------------------
    Then I went to the form element holding the date-of-birth information and, on the box to "Run macro on Exit" I entered the name of my macro.

    Now, when the user enters a date and hits the TAB key, it will verify that there is a valid date entered and, if there is, will unprotect the document, enter the age, and protect the document again with our reseting the info already there. Since I use DateDiff, the macro checks to see if the birthdate for the current year had been reached or not.

    Finally, I made sure that the macro was included in the macros for the template itself.

    Hope this helps. If anyone can reduce the amount of code or make it more efficient, please let me know.

Posting Permissions

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