Results 1 to 10 of 10
  1. #1
    Star Lounger
    Join Date
    Apr 2002
    Posts
    69
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Error Trapping (Word 2000 & 97)

    I do have a macro that deals with autocorrect entry. I want the macro to work on both Word 2000 & 97. Here is the macro. I tried to trap the eror. For example, in word 2000 and whan the code inside the if statement to execute, in word 97 I don't want it. For any reason, when I tried it in wod 97, it also wen insdie the if statement, then produced an error.

    With AutoCorrect
    On Error Resume Next
    If Err <> 0 Then
    .ReplaceTextFromSpellingChecker = False 'does not exist in word 97
    .CorrectKeyboardSetting = False 'does not exist in word 97
    End If
    .CorrectInitialCaps = True
    .CorrectSentenceCaps = True
    .CorrectDays = True
    .CorrectCapsLock = True
    .ReplaceText = True
    End With

    The error I got from Word 97 did not produce an error message. Therefor I could not get an error gode. I received an eror message "compiler error: method or data member not found"

  2. #2
    Gold Lounger
    Join Date
    Dec 2000
    Location
    New Hampshire, USA
    Posts
    3,386
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Error Trapping (Word 2000 & 97)

    Use the VBA6 compiler constant to select which coderuns only in Word 2000 and beyond.

    #IF VBA6 then
    ' VBA 6 code here
    #ELSE
    ' VBA 5 code here
    #End If

  3. #3
    Star Lounger
    Join Date
    Apr 2002
    Posts
    69
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Error Trapping (Word 2000 & 97)

    Thank you, it works fine. I did not know about these compiler constants

  4. #4
    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: Error Trapping (Word 2000 & 97)

    Alternatively, if the feature has more to do with the application version and less to do with the language version, you can test the application version:

    if Application.Version = "9.0" Then 'Word 2000

    Select Case Application.Version
    Case "8.0" 'Office 97
    Case Else 'Office 2000, XP, ...

  5. #5
    Star Lounger
    Join Date
    Apr 2002
    Posts
    69
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Error Trapping (Word 2000 & 97)

    Thank you for the new trick

  6. #6
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Error Trapping (Word 2000 & 97)

    The #IF directive will do the correct thing with Properties and Methods that produce compile time errors. I think that the Application.Version check is a run time thing, so the compile errors would still occur.

    StuartR

  7. #7
    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: Error Trapping (Word 2000 & 97)

    That's a good point. I don't know why I have never run into that before.

    I wonder how you are supposed to handle that as between 2000 and XP if they both use VBA6?? What's New for Microsoft Word 2002 Developers lists such useful sounding objects as FootnoteOptions, that might seem to be applicable to earlier versions. Not sure there's a backwards compatibility test that will work for that.

  8. #8
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Error Trapping (Word 2000 & 97)

    This is a Friday night just before I go to bed, untested thought...

    I wonder if you could have XP and 2000 routines with different names in different modules. Choose which routine to call based on your Application.Version check. I don't think you would get the compile error if you didn't execute any code in the module.

    StuartR

  9. #9
    Gold Lounger
    Join Date
    Dec 2000
    Location
    New Hampshire, USA
    Posts
    3,386
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Error Trapping (Word 2000 & 97)

    MSFT screwed up by not providing a compiler constant to distinguish 'tween Word 2000 and Word 2002.

  10. #10
    Gold Lounger
    Join Date
    Dec 2000
    Location
    New Hampshire, USA
    Posts
    3,386
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Error Trapping (Word 2000 & 97)

    Yes, you can do that.

    You can also get sneaky and use Application.Run to run code.

    But this still does not overcome the problem of not being able to Compile to catch typos, etc.

Posting Permissions

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