473,320 Members | 1,881 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Automation against multiple MS Word versions

If one is developing a .NET application, how can I develop an application
that uses COM automation that targets multiple versions of Word? For
example, the signature for the Document.Open method is different from
version 9 to version 11 (and I'm sure there are other variations as well),
and I'm wondering if there's some easy way to deal with it.

At present I'm only concerned with supporting 9-11 (i.e. Word 2000, XP, and
2003), though I'd like to be flexible enough to deal with future versions as
well. How are developers dealing with this sticky situation now?

evan stone | software engineer
----------------------------------------
santa rosa, ca, usa
Nov 17 '05 #1
12 2960
Evan,

Unfortunately, there is no good solution for this. For something like
this, you will have to determine the version of Word you are using, and make
the appropriate call. This will also mean having references to the interop
assemblies for all three versions.

Given that the newer versions should support the older interfaces, you
might have some luck for most of the properties/methods, since you can
always downcast to the lowest version of the interface you will support.

However, if you need to do something different based on the version that
you have, you should probably write a utility class which will expose
methods which take the interface pointer, a version, and the parameters for
the operation, which will contain the separate logic.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Evan Stone" <re*********************@hotmail.com> wrote in message
news:OS*************@tk2msftngp13.phx.gbl...
If one is developing a .NET application, how can I develop an application
that uses COM automation that targets multiple versions of Word? For
example, the signature for the Document.Open method is different from
version 9 to version 11 (and I'm sure there are other variations as well),
and I'm wondering if there's some easy way to deal with it.

At present I'm only concerned with supporting 9-11 (i.e. Word 2000, XP,
and
2003), though I'd like to be flexible enough to deal with future versions
as
well. How are developers dealing with this sticky situation now?

evan stone | software engineer
----------------------------------------
santa rosa, ca, usa

Nov 17 '05 #2
Office automation is pure evil.

--

Derek Davis
dd******@gmail.com

"Evan Stone" <re*********************@hotmail.com> wrote in message
news:OS*************@tk2msftngp13.phx.gbl...
If one is developing a .NET application, how can I develop an application
that uses COM automation that targets multiple versions of Word? For
example, the signature for the Document.Open method is different from
version 9 to version 11 (and I'm sure there are other variations as well),
and I'm wondering if there's some easy way to deal with it.

At present I'm only concerned with supporting 9-11 (i.e. Word 2000, XP,
and
2003), though I'd like to be flexible enough to deal with future versions
as
well. How are developers dealing with this sticky situation now?

evan stone | software engineer
----------------------------------------
santa rosa, ca, usa

Nov 17 '05 #3
> Unfortunately, there is no good solution for this.

It figures.
For something like
this, you will have to determine the version of Word you are using, and make the appropriate call. This will also mean having references to the interop assemblies for all three versions.


Is it possible to set references to multiple type libraries within one
assembly? How does that work - is VS.NET smart enough to create separate
namespaces for the different versions of the assemblies so we can
differentiate at runtime?

Or, would it make sense to create 3 (for now) assemblies that each have one
reference to each Word Interop assembly, and then use a Factory pattern to
instantiate the appropriate version of a wrapper object designed to handle
its corresponding version?

Then there's the matter of determining the version of Word that they have
installed, which is another problem to deal with as well (but probably less
tricky)....

evan stone | software engineer
----------------------------------------
santa rosa, ca, usa
Nov 17 '05 #4
Evan,

See inline:
Is it possible to set references to multiple type libraries within one
assembly? How does that work - is VS.NET smart enough to create separate
namespaces for the different versions of the assemblies so we can
differentiate at runtime?
No, it is not.
Or, would it make sense to create 3 (for now) assemblies that each have
one
reference to each Word Interop assembly, and then use a Factory pattern to
instantiate the appropriate version of a wrapper object designed to handle
its corresponding version?
Yes, it would. However, you would have to take care of the situations
where the interface differs. This would involve you having to create your
own interface, which in turn would check the version on those "tricky"
calls, and make the call to the appropriate interface.

Then there's the matter of determining the version of Word that they have
installed, which is another problem to deal with as well (but probably
less
tricky)....
I believe there is a registry setting which will tell you this.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

evan stone | software engineer
----------------------------------------
santa rosa, ca, usa

Nov 17 '05 #5
> Office automation is pure evil.

Agreed. But sometimes a necessary evil, unfortunately...

evan stone | software engineer
----------------------------------------
santa rosa, ca, usa
Nov 17 '05 #6
Inline.
Is it possible to set references to multiple type libraries within one
assembly? How does that work - is VS.NET smart enough to create separate
namespaces for the different versions of the assemblies so we can
differentiate at runtime?


No, it is not.


Neato!

....but it's also as I figured, so whatever.
Or, would it make sense to create 3 (for now) assemblies that each have
one
reference to each Word Interop assembly, and then use a Factory pattern to instantiate the appropriate version of a wrapper object designed to handle its corresponding version?


Yes, it would. However, you would have to take care of the situations
where the interface differs. This would involve you having to create your
own interface, which in turn would check the version on those "tricky"
calls, and make the call to the appropriate interface.


This is the scenario that I was originally planning for. I was planning on
writing an Adapter that would provide a *consistent* interface that the rest
of my application would interact with, and then pass the calls to the
appropriate underlying component.
Then there's the matter of determining the version of Word that they have installed, which is another problem to deal with as well (but probably
less
tricky)....


I believe there is a registry setting which will tell you this.


OK. I'll check this out... I'm sure it's fairly easy to do, and is not one
of my major concerns at this point.

Thanks for the information, Nicholas. You've been most helpful.

:)

evan stone | software engineer
----------------------------------------
santa rosa, ca, usa
Nov 17 '05 #7
Nicholas,

One more thing....

Do you have any idea as to how to get hold of the various .OLB type library
files one would need to accomplish what I'm hoping to do? Actually I *think*
I can get my hands on the v10 and v11 typelibs, but I'm not sure if I have
v9 around anywhere...

Thanks!

evan stone | software engineer
----------------------------------------
santa rosa, ca, usa
Nov 17 '05 #8
Evan,

If you have the original installs of those products, then you should be
able to get the type libraries.

Also, I forgot one thing. The recommendation that you use different
namespaces for the different versions can actually be done. Instead of
setting a reference in VS.NET to the COM object, use the TLBIMP utility to
generate the type libraries. That utility will allow you to specify the
namespace that the types in the assembly are in.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- ca*******@caspershouse.com

"Evan Stone" <re*********************@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
Nicholas,

One more thing....

Do you have any idea as to how to get hold of the various .OLB type
library
files one would need to accomplish what I'm hoping to do? Actually I
*think*
I can get my hands on the v10 and v11 typelibs, but I'm not sure if I have
v9 around anywhere...

Thanks!

evan stone | software engineer
----------------------------------------
santa rosa, ca, usa

Nov 17 '05 #9
Not if you choose the right tools, and C# is not such tool, programming
against Office is where VB.NET has got it over C# hands-down. For example
VB.NET supports late binding at the language level, no need to resort to
reflection, VB.NET supports optional parameters, named parameters and
passing expressions to ref. parameters, whereas C# does not.

Willy.
"carion1" <dd******@gmail.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
Office automation is pure evil.

--

Derek Davis
dd******@gmail.com

"Evan Stone" <re*********************@hotmail.com> wrote in message
news:OS*************@tk2msftngp13.phx.gbl...
If one is developing a .NET application, how can I develop an application
that uses COM automation that targets multiple versions of Word? For
example, the signature for the Document.Open method is different from
version 9 to version 11 (and I'm sure there are other variations as
well),
and I'm wondering if there's some easy way to deal with it.

At present I'm only concerned with supporting 9-11 (i.e. Word 2000, XP,
and
2003), though I'd like to be flexible enough to deal with future versions
as
well. How are developers dealing with this sticky situation now?

evan stone | software engineer
----------------------------------------
santa rosa, ca, usa


Nov 17 '05 #10
> If you have the original installs of those products, then you should
be
able to get the type libraries.


I'm sure we've got Office 2000 around here somewhere. It's just a matter of
getting the OLB file and then using the TLBIMP utility to generate the type
libraries, correct? I just found out about the TLBIMP utility this morning,
so it's interesting that you mentioned it as well.

I'll take a look at it, but for now I seem to have a handle on things. I
still need to generate libraries for Office 2000 (v9), however, but it's not
urgent at the moment. I'm hoping that I can develop to the version 9
interface and all will be well, per the info in the MS KB.

Thanks!

evan stone | software engineer
----------------------------------------
santa rosa, ca, usa

Nov 17 '05 #11
> Not if you choose the right tools, and C# is not such tool, programming
against Office is where VB.NET has got it over C# hands-down. For example
VB.NET supports late binding at the language level, no need to resort to
reflection, VB.NET supports optional parameters, named parameters and
passing expressions to ref. parameters, whereas C# does not.


Very interesting. Actually I'm finding the automation with C# to be not as
bad as I had originally thought it would be. However, if using VB.NET would
make it much easier, then perhaps writing an Adapter/Wrapper in VB.NET that
could be consumed by the rest of my C# application might make a lot of
sense. For the time being, C# has been working fine, but if I really have to
do some hardcore automation then perhaps I might do exactly that.

Thanks for the suggestion!

evan stone | software engineer
----------------------------------------
santa rosa, ca, usa
Nov 17 '05 #12
> Instead of setting a reference in VS.NET to the COM object,
use the TLBIMP utility to generate the type libraries.
That utility will allow you to specify the
namespace that the types in the assembly are in.


Will TLBIMP create the four DLLs I need:

- Interop.Office.dll
- Interop.VBIDE.dll
- Interop.Word.dll
- office.dll

Thanks!

evan stone | software engineer
----------------------------------------
santa rosa, ca, usa
Nov 17 '05 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Mike MacSween | last post by:
Office 2000 From Access I've been starting an instance of word and doing a mail merge. Everything hunky-dory until I applied SP1 yesterday. Now this: dim wrd as Object set wrd =...
25
by: Neil Ginsberg | last post by:
I have a strange situation with my Access 2000 database. I have code in the database which has worked fine for years, and now all of a sudden doesn't work fine on one or two of my client's...
12
by: Cheval | last post by:
Has anyone had any problems with inter-office automation between MS Word and MS Access in Office 2003? I have recently installed office 2003 in a new folder and have left the older office 2000...
2
by: Mystery Man | last post by:
We are developing a C# application that has many interfaces to the Microsoft suite (eg Word, Excel, Outlook, Powerpoint, etc). We need to support Office 97, 2000, 2002 and any future versions. ...
0
by: Zoury | last post by:
Hello! I'm using the Microsoft Word 11.0 Object Library in my project. This means the client must have Word 2003 on his computer to run my app properly. What if I want my app to support...
17
by: Mansi | last post by:
I need to do some research on how to use excel automation from c#. Does anyone know of any good books related to this subject? Thanks. Mansi
0
by: Marco Singer | last post by:
Hi all, I want to create an Office automation client for Office 97 (and newer) which should automate Access, Excel and Word. On my developer computer I have Office XP installed. In KB244167...
1
by: Evan Stone | last post by:
If one is developing a .NET application, how can I develop an application that uses COM automation that targets multiple versions of Word? For example, the signature for the Document.Open method is...
9
by: Chubbly Geezer | last post by:
Hope you can help. I have created a mail merge word doc which seems to work fine. When I close and reload it asks if I wish to pull in the data. Great. However, I want to print the results of...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.