Results 1 to 14 of 14
  1. #1
    2 Star Lounger
    Join Date
    Jan 2001
    Posts
    117
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Word 2000 macro doesn't work in Word 97 (Word 2000/Word 97)

    I wrote a macro in Word 2000 and gave it to someone who is using Word 97. When running it in Word 97, she gets an error message that says: "Compile Error: Variable not defined."

    I know that all of the variables are properly defined, and it functioned well in Word 2000. What do I need to do to get the macro to work in Word 97 as well as Word 2000? I'm not familiar with the differences in VBA between the versions.

    - Linda

  2. #2
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Word 2000 macro doesn't work in Word 97 (Word 2000/Word 97)

    Linda,

    There are a number of objects, properties and methods that are available in Word 2000 VBA, which are not available in Word 97 VBA. If your code contains a reference to any of these, it's likely to produce a compile error when you try to run it in Word 97.

    The most efficient way to track these down would be to go to the VB Editor (while in Word 97) and open the project containing the code. Then click on Debug >Compile [ProjectName]. The offending pieces of code will be highlighted (in turn).

    It's almost certain that the highlighted code will relate to features that are in Word 2000 but not in Word 97. It would be interesting to see what code is causing the problem, so if you can track it down, post back.

    Gary

  3. #3
    2 Star Lounger
    Join Date
    Jan 2001
    Posts
    117
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Word 2000 macro doesn't work in Word 97 (Word 2000/Word 97)

    Thank you, Gary! You're right--here are the lines of code that Word 97 couldn't handle:

    ActiveDocument.Styles("StyleName").Font.UnderlineC olor = wdColorAutomatic

    'In the following, Word 97 couldn't recognize
    'wdWord9TableBehavior and wdAutoFitFixed
    ActiveDocument.Tables.ADD Range:=Selection.Range, NumRows:=1, NumColumns:= _
    2, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:= _
    wdAutoFitFixed

    Selection.Tables(1).BottomPadding = InchesToPoints(0.2)

    Selection.Tables(1).Columns(1).PreferredWidthType = wdPreferredWidthPoints

    Selection.Tables(1).Columns(1).PreferredWidth = InchesToPoints(1#)

    ActiveWindow.ActivePane.View.Type = wdPrintView

    So...now I need to find the proper code for Word 97. I believe I recorded all of these originally, so I think I'll be able to figure it out.

    Can my VBA code identify whether the computer is running Word 97 or Word 2000 (or another version)? I'd like to avoid having separate macros for different versions, if I can.

    - Linda

  4. #4
    2 Star Lounger
    Join Date
    Mar 2001
    Location
    Oregon, USA
    Posts
    129
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Word 2000 macro doesn't work in Word 97 (Word 2000/Word 97)

    Hi Linda,

    You could try this as a starter:

    <pre>If Application.Version = "8.0" Then
    ' do Word 97 stuff
    ElseIf Application.Version = "9.0" Then
    'do Word 2000 stuff
    Else
    'do Word X(treme)P(rofit) stuff
    End If
    </pre>


    I seem to recall patches to one version changing the Application.Version number so that I had to use a range, but I can't remember which version.

    HTH,

    Chris

  5. #5
    Platinum Lounger
    Join Date
    Dec 2000
    Location
    Queanbeyan, New South Wales, Australia
    Posts
    3,730
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Word 2000 macro doesn't work in Word 97 (Word 2000/Word 97)

    If there's compiler problems, then Application.version won't help.

    You would need a conditional compile:

    #If VBA6 Then
    MsgBox "Word 2000"
    #Else
    MsgBox "Word 97"
    #End If

    I don't know that there is an equivalent though for Office XP.
    Subway Belconnen- home of the Signboard to make you smile. Get (almost) daily updates- follow SubwayBelconnen on Twitter.

  6. #6
    5 Star Lounger jujuraf's Avatar
    Join Date
    Jun 2001
    Location
    San Jose, California, USA
    Posts
    1,061
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Word 2000 macro doesn't work in Word 97 (Word 2000/Word 97)

    I'd recommend a variation to this code that handles the sevice releases:
    if (instr(1, application.version, "8.") = 1 then msgbox "This is Excel 97"

    if (instr(1, application.version, "9.") = 1 then msgbox "This is Excel 2000"

    if (instr(1, application.version, "10.") = 1 then msgbox "This is Excel XP"

    This will handle things like 9.1 or 10.2, etc.

    I have found TONS of undocumented differences in the VBA for xl97 and xl2000 which have nothing to do with the new objects in xl2000. I have had to spend way too much time finding the same set of code that works in both versions without having to resort to writing multiple code ("if Excel97 then doThis else doThat"). This is a huge pet peeve of mine and has greatly extended the time it took me to finish my project. I don't even want to know what havoc ExcelXP will bring me.

    Deb <img src=/S/bummer.gif border=0 alt=bummer width=15 height=15>

  7. #7
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Word 2000 macro doesn't work in Word 97 (Word 2000/Word 97)

    Office XP is still VBA6.
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  8. #8
    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: Word 2000 macro doesn't work in Word 97 (Word 2000/Word 97)

    If the error is an unrecognized "variable", then perhaps the constant is a new one in Word2000. You could debug.print the constant in the Immediate window to get its numeric value and then try that in Word97. However, some values might be new to Word2000.

  9. #9
    2 Star Lounger
    Join Date
    Mar 2001
    Location
    Oregon, USA
    Posts
    129
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Word 2000 macro doesn't work in Word 97 (Word 2000/Word 97)

    Ooh. Good catch. I totally spaced that. We've got both 97 and 2000 installs and have been writing in 97. Compiler issues haven't been an issue. We're upgrading everyone to 2000 in a few days. Two things I love in 2000: InstrRev and Replace.

    Thanks Geoff,

    Chris

  10. #10
    5 Star Lounger jujuraf's Avatar
    Join Date
    Jun 2001
    Location
    San Jose, California, USA
    Posts
    1,061
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Word 2000 macro doesn't work in Word 97 (Word 2000/Word 97)

    Yes, I know that, but my point was that ExcelXP returns "10.x" as its version number so that's how you know it's XP. So far there is no VBA.NET (thank God!)

    Deb <img src=/S/crazy.gif border=0 alt=crazy width=15 height=15>

  11. #11
    Platinum Lounger
    Join Date
    Dec 2000
    Location
    Queanbeyan, New South Wales, Australia
    Posts
    3,730
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Word 2000 macro doesn't work in Word 97 (Word 2000/Word 97)

    Kevin,

    I was afraid of that.

    I have the feeling this was raised before- probably in the demised forum, because I cannot find it any more.

    The constant was very useful between Office 97 and Office 2000.

    As I remember, the poster was beta testing XP- and as a result of the interchange in the forum, raised a fault request- which was ignored.
    Subway Belconnen- home of the Signboard to make you smile. Get (almost) daily updates- follow SubwayBelconnen on Twitter.

  12. #12
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Word 2000 macro doesn't work in Word 97 (Word 2000/Word 97)

    Geoff,

    That tester was ME! I was one of the multitudes of beta testers. I submitted a bug report on the issue. (It sure seemed like a bug to me -- no compiler directive to differentiate Word 2002 code from 2000 code???) A nice guy named Tom replied that the compiler directive VBA6 would not change as the VBA "kernel" was the same.

    I still consider it a bug.
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  13. #13
    2 Star Lounger
    Join Date
    Jan 2001
    Posts
    117
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Word 2000 macro doesn't work in Word 97 (Word 2000/Word 97)

    Just a little follow-up: The conditional compile code suggested by Geoff worked for me, and I was able to resolve all the Word 97 compiler problems. Whew! Thanks to everyone for helping me out!

    I am wondering if there's a way to check specifically if the version is Word 97. I guessed at VBA5, but it didn't seem to work....

    - Linda

  14. #14
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Dublin, Ireland, Republic of
    Posts
    2,697
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Word 2000 macro doesn't work in Word 97 (Word 2000/Word 97)

    Linda,

    Application.Version returns the version number or you can also use Application.Build which a gives a bit more info. If either return 8.x, then it is Word 97. 9.x is returned for Word 2000.

    Andrew

Posting Permissions

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