Run time error 9118 Parameter value was out of acceptable range

G

Guy Cohen

Hi all,

Using: VB6, SP5
Referencing: Microsoft Word 8.0 Object Library.

Call .ConvertToTable(vbTab, , , , wdTableFormatElegant, , , , , , , , ,
True)

I use the above on a range object to create a table in a word document
generated by pure VB code.
When I have Word97 installed on my machine - its working fine.
However, when I install Word2000 the RTE happens.

The RTE happens only when I have Word 2000.
I already tried to change the True value to 1 as suggested in some articles
in the web.
I also tried to remove all the parameters but the first vbTab and it did not
help as well :(

Please advise
TIA
Guy
 
P

Perry

Hi Guy,

Try to use the values instead of the enumerated Word constants
? wdTableFormatElegant
36

So replace
Call .ConvertToTable(vbTab, , , , wdTableFormatElegant, , , , , , , , ,
True)
by
Call .ConvertToTable(vbTab, , , , 36, , , , , , , , ,True)

Kindly repost if still not working.

Krgrds,
Perry
 
G

Guy Cohen

Hi Perry.

I used 36 as suggested + checked and it did not work (same RTE).

As I wrote (read below) - I removed all the parameters and left vbTab as the
separator and it also did not work (same RTE)

Please kindly advise again
Guy
 
P

Perry

You might consider raising the parameter names, like in:
MyRange.ConvertToTable seperator:=vbTab, Format:=36

As long as the parameters are used and recognized by both Word97 as well as
Word2K.

I've included two links to differentiate usage of parameters in both Office
97 as opposed
to usage of ConvertToTable function in Office 2K.

This is the document regarding usage of ConvertToTable in Office97
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/office97/ht
ml/output/f1/d4/s5a98a.asp

This is the same function, in Office 10/2k
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbawd10/htm
l/womthconverttotable.asp

Krgrds,
Perry
 
J

Jeff Johnson [MVP: VB]

Using: VB6, SP5
Referencing: Microsoft Word 8.0 Object Library.

Call .ConvertToTable(vbTab, , , , wdTableFormatElegant, , , , , , , , ,
True)

I use the above on a range object to create a table in a word document
generated by pure VB code.
When I have Word97 installed on my machine - its working fine.
However, when I install Word2000 the RTE happens.

The RTE happens only when I have Word 2000.

The object libraries are different for every version of Word. If you're
referencing 8.0 (Word 97) and you try to run against Word 2000 (9.0), I'm
not at all surprised that you're getting errors. If you must support
different versions, you should drop all Word library references and go with
late binding using CreateObject().
 
G

Guy Cohen

Hi Jeff,

I used createobject as suggested+removed the references.
The code is working fine now on my machine (with office 2000)- should check
with the client ... :)

However, I am not sure that what I did is wrong (you wrote: I'm not at all
surprised that you're getting errors)
As I have Word2000 on my machine - It should be compatible with Word97
objects. If the case was the other way around... (Client has W2000 and I
have W97) - Then it would be funny to try and do W2000 stuff on W97.

Thanks a lot anyway (Y)
Guy
 
T

Thomas Winter

Jeff Johnson said:
The object libraries are different for every version of Word. If you're
referencing 8.0 (Word 97) and you try to run against Word 2000 (9.0), I'm
not at all surprised that you're getting errors. If you must support
different versions, you should drop all Word library references and go with
late binding using CreateObject().

That's not true at all. COM/ActiveX/Automation was designed so you could
continue to use future versions of the same objects, etc. I have written
quite a large project in VB that references the Word 9.0 (2000) object
library and it runs just fine on Word 97, Word 2000, Word 2002 and Word
2003. (Fully tested on all of them). I just had to make sure I watched out
for changes in the object model, such as new parameters, new objects, new
methods, etc. and made sure I did not use any that were not available in all
versions of Word.

-Tom
 
J

Jeff Johnson [MVP: VB]

That's not true at all. COM/ActiveX/Automation was designed so you could
continue to use future versions of the same objects, etc. I have written
quite a large project in VB that references the Word 9.0 (2000) object
library and it runs just fine on Word 97, Word 2000, Word 2002 and Word
2003. (Fully tested on all of them). I just had to make sure I watched out
for changes in the object model, such as new parameters, new objects, new
methods, etc. and made sure I did not use any that were not available in all
versions of Word.

And what happens when you distribute this application to someone who only
has Word 97 installed? Are you distributing the 9.0 .TLB? If so, are you
legally permitted to do so?
 
T

Thomas Winter

Jeff Johnson said:
,
,

That's not true at all. COM/ActiveX/Automation was designed so you could
continue to use future versions of the same objects, etc. I have written
quite a large project in VB that references the Word 9.0 (2000) object
library and it runs just fine on Word 97, Word 2000, Word 2002 and Word
2003. (Fully tested on all of them). I just had to make sure I watched out
for changes in the object model, such as new parameters, new objects, new
methods, etc. and made sure I did not use any that were not available in all
versions of Word.

And what happens when you distribute this application to someone who only
has Word 97 installed? Are you distributing the 9.0 .TLB? If so, are you
legally permitted to do so?

(First off I'll admit I wasn't quite right in what I said above. I'll
explain below.)

I runs just fine. I'm not distributing anything but the VB runtime.

I would recommend you check out this article:

Building, Versioning, and Maintaining Visual Basic Components
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnvb600/html/msdn_bldvbcom.asp

While Word obviously isn't written in VB, the same basic rules apply. Check
out the section that talks about Compatibility Options in Visual Basic.
Thinking in VB terms, Word's type library (MSWORD.OLB) has always been
recompiled with what amounts to "binary compatibility", so that our programs
could continue to work with newer (or older if we're careful) versions of
Word.

Look in Table 1 in the article where it talks about version numbers of the
type library. If you use OLE View to look at Word's type library
(MSWORD.OLB), you'll find that the Word 97 and Word 2003 versions both have
the same GUID for the type library. Word 97's type library version is 8.0
and Word 2003's is 8.3. (From this we can guess that Word 2000 was 8.1 and
Word 2002 was 8.2). You'll notice the same type of thing with the versioning
if you go look at the various interfaces (classes) in OLE View.

If you want to download OLE View, go here:
http://www.microsoft.com/com/resources/oleview.asp

Here's another really good article:
Visual Basic Design Time Techniques to Prevent Runtime Version Conflicts
http://www.microsoft.com/msj/0100/versioning/versioning.aspx

Now, what this means is that you should never have a problem going FORWARD.
That is, if you compile your VB projects referencing the Word 97 type
library, they will always work no problem with newer versions of Word.
That's the whole point of compatibility. Microsoft wants it to work that
way. If you want to use some methods or objects from newer versions of Word,
use late binding. That is, declare your variables as Object, rather than
Word.Application, for example, and then check the version of Word and call
the methods as needed. You won't get Intellisense, and it will run slighlty
slower, but that's what you gotta do. Now if you ask, "Why don't I just
reference the Word 2003 type library, do version checking and forget about
Diming As Object?" That's where you run into problems!

(OK, I admit, I only just figured this out as I'm writting this!)

It's pretty interesting if you look at the Word 2003 MSWORD.OLB and look at
the Documents interface. You'll see methods called OpenOld, Open2000,
Open2002 and Open. This is because each version of Word has added parameters
to the Open method (OpenOld is Word 97's version). This is because of the
rules of COM, you can't change an all ready published method signature. So
Word 2000 and later add a new Open method, renaming the old one. It's there,
you just can't see it in VB or VBA since its "hidden".

The difficulties come if you compile your VB project while referencing (for
example) the Word 2003 type library. Any calls to Open will be compiled to
use the Word 2003 version of Open. If you then run your project on a Word
97-only system, it will crash with a COM exception, because it is trying to
use a method that does not exist in Word 97. (You can test this for yourself
if you have multiple versions of Word on your machine. Start a quick VB
project, reference a Word 2000 or later Type Library, and call the Open
method. Compile It. Then start Word 97 and run the program, You'll get a
nasty error message.)

Now, as I said, I compiled my project referencing the Word 2000 type library
and it runs fine on Word 97-only systems. Why? Well, two reasons. First,
you'll only have problems if you try to reference methods that have changed
from one version of Word to the next. (The Word help file is happy to tell
you about NEW objects, methods and events, but of course it doesn't tell you
about CHANGED methods, what we are concerned about here.) For example, the
Save method of the Documents object hasn't changed at all up to Word 2003,
so you won't have any problem using it. Second, I used late binding to call
the Open and Add methods of the Documents object. If you use late binding it
will always call the most current version of the method, whatever is happens
to be.

This type of stuff MIGHT explain the difficulties Guy is having using the
ConvertToTable method. The ConvertToTable method has changed from Word 97 to
Word 2000 (parameters where added). If he compiled his project while
referencing the Word 2000 type library, then tried to run it on a Word
97-only machine, he would get an run-time error. Switching to late-binding
(he used CreateObject, etc.) would fix the problem, as it did. The funny
thing is that he compiled under Word 97, in which case he shouldn't have any
problems.

I hope I've explained this well. If not, let me know and I'll try again!

-Tom
 
T

Thomas Winter

Jeff Johnson said:
,
,

That's not true at all. COM/ActiveX/Automation was designed so you could
continue to use future versions of the same objects, etc. I have written
quite a large project in VB that references the Word 9.0 (2000) object
library and it runs just fine on Word 97, Word 2000, Word 2002 and Word
2003. (Fully tested on all of them). I just had to make sure I watched out
for changes in the object model, such as new parameters, new objects, new
methods, etc. and made sure I did not use any that were not available in all
versions of Word.

And what happens when you distribute this application to someone who only
has Word 97 installed? Are you distributing the 9.0 .TLB? If so, are you
legally permitted to do so?

(Sorry if this gets posted twice. My Outlook Express seems to be acting
weird. Surprise, surprise!)

(First off I'll admit I wasn't quite right in what I said above. I'll
explain below.)

I runs just fine. I'm not distributing anything but the VB runtime.

I would recommend you check out this article:

Building, Versioning, and Maintaining Visual Basic Components
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnvb600/html/msdn_bldvbcom.asp

While Word obviously isn't written in VB, the same basic rules apply. Check
out the section that talks about Compatibility Options in Visual Basic.
Thinking in VB terms, Word's type library (MSWORD.OLB) has always been
recompiled with what amounts to "binary compatibility", so that our programs
could continue to work with newer (or older if we're careful) versions of
Word.

Look in Table 1 in the article where it talks about version numbers of the
type library. If you use OLE View to look at Word's type library
(MSWORD.OLB), you'll find that the Word 97 and Word 2003 versions both have
the same GUID for the type library. Word 97's type library version is 8.0
and Word 2003's is 8.3. (From this we can guess that Word 2000 was 8.1 and
Word 2002 was 8.2). You'll notice the same type of thing with the versioning
if you go look at the various interfaces (classes) in OLE View.

If you want to download OLE View, go here:
http://www.microsoft.com/com/resources/oleview.asp

Here's another really good article:
Visual Basic Design Time Techniques to Prevent Runtime Version Conflicts
http://www.microsoft.com/msj/0100/versioning/versioning.aspx

Now, what this means is that you should never have a problem going FORWARD.
That is, if you compile your VB projects referencing the Word 97 type
library, they will always work no problem with newer versions of Word.
That's the whole point of compatibility. Microsoft wants it to work that
way. If you want to use some methods or objects from newer versions of Word,
use late binding. That is, declare your variables as Object, rather than
Word.Application, for example, and then check the version of Word and call
the methods as needed. You won't get Intellisense, and it will run slighlty
slower, but that's what you gotta do. Now if you ask, "Why don't I just
reference the Word 2003 type library, do version checking and forget about
Diming As Object?" That's where you run into problems!

(OK, I admit, I only just figured this out as I'm writting this!)

It's pretty interesting if you look at the Word 2003 MSWORD.OLB and look at
the Documents interface. You'll see methods called OpenOld, Open2000,
Open2002 and Open. This is because each version of Word has added parameters
to the Open method (OpenOld is Word 97's version). This is because of the
rules of COM, you can't change an all ready published method signature. So
Word 2000 and later add a new Open method, renaming the old one. It's there,
you just can't see it in VB or VBA since its "hidden".

The difficulties come if you compile your VB project while referencing (for
example) the Word 2003 type library. Any calls to Open will be compiled to
use the Word 2003 version of Open. If you then run your project on a Word
97-only system, it will crash with a COM exception, because it is trying to
use a method that does not exist in Word 97. (You can test this for yourself
if you have multiple versions of Word on your machine. Start a quick VB
project, reference a Word 2000 or later Type Library, and call the Open
method. Compile It. Then start Word 97 and run the program, You'll get a
nasty error message.)

Now, as I said, I compiled my project referencing the Word 2000 type library
and it runs fine on Word 97-only systems. Why? Well, two reasons. First,
you'll only have problems if you try to reference methods that have changed
from one version of Word to the next. (The Word help file is happy to tell
you about NEW objects, methods and events, but of course it doesn't tell you
about CHANGED methods, what we are concerned about here.) For example, the
Save method of the Documents object hasn't changed at all up to Word 2003,
so you won't have any problem using it. Second, I used late binding to call
the Open and Add methods of the Documents object. If you use late binding it
will always call the most current version of the method, whatever is happens
to be.

This type of stuff MIGHT explain the difficulties Guy is having using the
ConvertToTable method. The ConvertToTable method has changed from Word 97 to
Word 2000 (parameters where added). If he compiled his project while
referencing the Word 2000 type library, then tried to run it on a Word
97-only machine, he would get an run-time error. Switching to late-binding
(he used CreateObject, etc.) would fix the problem, as it did. The funny
thing is that he compiled under Word 97, in which case he shouldn't have any
problems.

I hope I've explained this well. If not, let me know and I'll try again!

-Tom
 
G

Guy Cohen

Bravo!!!
??"Thomas Winter said:
,

(Sorry if this gets posted twice. My Outlook Express seems to be acting
weird. Surprise, surprise!)

(First off I'll admit I wasn't quite right in what I said above. I'll
explain below.)

I runs just fine. I'm not distributing anything but the VB runtime.

I would recommend you check out this article:

Building, Versioning, and Maintaining Visual Basic Components
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnvb600/html/msdn_bldvbcom.asp

While Word obviously isn't written in VB, the same basic rules apply. Check
out the section that talks about Compatibility Options in Visual Basic.
Thinking in VB terms, Word's type library (MSWORD.OLB) has always been
recompiled with what amounts to "binary compatibility", so that our programs
could continue to work with newer (or older if we're careful) versions of
Word.

Look in Table 1 in the article where it talks about version numbers of the
type library. If you use OLE View to look at Word's type library
(MSWORD.OLB), you'll find that the Word 97 and Word 2003 versions both have
the same GUID for the type library. Word 97's type library version is 8.0
and Word 2003's is 8.3. (From this we can guess that Word 2000 was 8.1 and
Word 2002 was 8.2). You'll notice the same type of thing with the versioning
if you go look at the various interfaces (classes) in OLE View.

If you want to download OLE View, go here:
http://www.microsoft.com/com/resources/oleview.asp

Here's another really good article:
Visual Basic Design Time Techniques to Prevent Runtime Version Conflicts
http://www.microsoft.com/msj/0100/versioning/versioning.aspx

Now, what this means is that you should never have a problem going FORWARD.
That is, if you compile your VB projects referencing the Word 97 type
library, they will always work no problem with newer versions of Word.
That's the whole point of compatibility. Microsoft wants it to work that
way. If you want to use some methods or objects from newer versions of Word,
use late binding. That is, declare your variables as Object, rather than
Word.Application, for example, and then check the version of Word and call
the methods as needed. You won't get Intellisense, and it will run slighlty
slower, but that's what you gotta do. Now if you ask, "Why don't I just
reference the Word 2003 type library, do version checking and forget about
Diming As Object?" That's where you run into problems!

(OK, I admit, I only just figured this out as I'm writting this!)

It's pretty interesting if you look at the Word 2003 MSWORD.OLB and look at
the Documents interface. You'll see methods called OpenOld, Open2000,
Open2002 and Open. This is because each version of Word has added parameters
to the Open method (OpenOld is Word 97's version). This is because of the
rules of COM, you can't change an all ready published method signature. So
Word 2000 and later add a new Open method, renaming the old one. It's there,
you just can't see it in VB or VBA since its "hidden".

The difficulties come if you compile your VB project while referencing (for
example) the Word 2003 type library. Any calls to Open will be compiled to
use the Word 2003 version of Open. If you then run your project on a Word
97-only system, it will crash with a COM exception, because it is trying to
use a method that does not exist in Word 97. (You can test this for yourself
if you have multiple versions of Word on your machine. Start a quick VB
project, reference a Word 2000 or later Type Library, and call the Open
method. Compile It. Then start Word 97 and run the program, You'll get a
nasty error message.)

Now, as I said, I compiled my project referencing the Word 2000 type library
and it runs fine on Word 97-only systems. Why? Well, two reasons. First,
you'll only have problems if you try to reference methods that have change d
from one version of Word to the next. (The Word help file is happy to tell
you about NEW objects, methods and events, but of course it doesn't tell you
about CHANGED methods, what we are concerned about here.) For example, the
Save method of the Documents object hasn't changed at all up to Word 2003,
so you won't have any problem using it. Second, I used late binding to call
the Open and Add methods of the Documents object. If you use late binding it
will always call the most current version of the method, whatever is happens
to be.

This type of stuff MIGHT explain the difficulties Guy is having using the
ConvertToTable method. The ConvertToTable method has changed from Word 97 to
Word 2000 (parameters where added). If he compiled his project while
referencing the Word 2000 type library, then tried to run it on a Word
97-only machine, he would get an run-time error. Switching to late-binding
(he used CreateObject, etc.) would fix the problem, as it did. The funny
thing is that he compiled under Word 97, in which case he shouldn't have any
problems.

I hope I've explained this well. If not, let me know and I'll try again!

-Tom
 

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