Type mismatch on Application.version

E

Edward Mendelson

Hello,

A user tells me that he gets a type mismatch error at these lines in some
code that seems to work for other other users. The code is:

Dim aVal as Long
aVal = Application.Version

Long and Integer work here, but I've seen other code that seems to treat
Application.Version as a string and uses

val(Application.Version)

Can anyone tell me what I *should* be using? I want to test for the
following conditions:

Word 97 (version 8)
Word 2000 and below (<= 9)
Word 2002 and above (>= 10)
Word 2002 (10)
Word 2003 (11)

In my copy of Word 2002 (SP3), if I enter ? Application.Version in the
Immediate window, it returns 10.0. But if I run this code:

Dim aVer As String
aVer = Val(Application.Version)
msgBox (aVer)
Debug.Print aVer

or this code:

Dim aVer As Single
aVer = Application.Version
msgBox (aVer)
Debug.Print aVer

both return 10 (no decimal).

Many thanks for any advice on this one.

Edward Mendelson
 
C

Cindy M -WordMVP-

Hi Edward,
A user tells me that he gets a type mismatch error at these lines in some
code that seems to work for other other users. The code is:

Dim aVal as Long
aVal = Application.Version
Application.Version returns a string. And even if you convert the string to
a number, that will be a decimal number (10.0, for example).

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :)
 
E

Edward Mendelson

Hi Cindy,

Many thanks for that quick answer. So, just to be certain, does that mean
that I can be fairly sure of avoiding a Type Mismatch by using code like
this:
.....
Dim aVer As Single
aVer = Val(Application.Version)
If aVer < 9.9 Then
msgBox "This macro is useful only in Word 2002 (Word XP) or later
versions.")
Exit Sub
End If

Thanks again!

Edward Mendelson
 
J

JSM

There is a version of Word - I think 97 - that returns "8.0b" therefore you
should always use a string variable. I usually check the value to the left
of the "."
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top