How do I support multiple versions of Word/Excel in C#?

M

Michael Howes

I have an application that needs to write Word and Excel files but
don't know which versions of Office will be installed on the users
machines. Either version 2000 or 2003
What is the easiest way to support both versions?

I wrote everything for 2003 (version 11) but on a machine with Office
2K I get an error (of course) because version 11 of Interop.Word and
Interop.Excel can't be found

Reference both versions, try and figure out what version is installed
in code, and create the correct object?

thanks
mike
 
J

Jonathan West

Michael Howes said:
I have an application that needs to write Word and Excel files but don't
know which versions of Office will be installed on the users machines.
Either version 2000 or 2003
What is the easiest way to support both versions?

I wrote everything for 2003 (version 11) but on a machine with Office 2K
I get an error (of course) because version 11 of Interop.Word and
Interop.Excel can't be found

Reference both versions, try and figure out what version is installed in
code, and create the correct object?

thanks
mike

When doing Office automation, you should always have the *oldest* version of
Office you want to support on your development machine, and set the objects
for compatibility with that.

You then test your completed app on a test machine with the newer version of
Office.

There are two important reasons why you should work this way.

1. The newer version of the object model has extra objects that the older
one doesn't. If you aren't careful, you will use some of them, and then have
terrible trouble debugging your application when testing on the older
version. Moving from older for development to newer for test is much less
likely to give you those problems. (There still may be an occasional
problem, but they will be far, far fewer)

2. The object references normally update themselves automatically when a
newer version of Office is detected, which means you can use early binding
on the old version of Office, and all should be well with the references
when you install on a machine with the newer version.

I suspect you have a fair bit of work still ahead of you.


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 
M

Michael Howes

1. The newer version of the object model has extra objects that the
older one doesn't. If you aren't careful, you will use some of them, and
then have terrible trouble debugging your application when testing on
the older version. Moving from older for development to newer for test
is much less likely to give you those problems. (There still may be an
occasional problem, but they will be far, far fewer)

2. The object references normally update themselves automatically when a
newer version of Office is detected, which means you can use early
binding on the old version of Office, and all should be well with the
references when you install on a machine with the newer version.

I suspect you have a fair bit of work still ahead of you.

thanks
I hope (and don't think) it will be that much work. The main reasons
being, I'm writing VERY simple documents and the code is complete and
tested on Word/Excel 2003.

My guess was that i'd need to reference the oldest version we are going
to support, which is Office 2000

thanks
mike
 
M

Michael Howes

1. The newer version of the object model has extra objects that the
older one doesn't. If you aren't careful, you will use some of them, and
then have terrible trouble debugging your application when testing on
the older version. Moving from older for development to newer for test
is much less likely to give you those problems. (There still may be an
occasional problem, but they will be far, far fewer)

2. The object references normally update themselves automatically when a
newer version of Office is detected, which means you can use early
binding on the old version of Office, and all should be well with the
references when you install on a machine with the newer version.

I suspect you have a fair bit of work still ahead of you.

thanks
I hope (and don't think) it will be that much work. The main reasons
being, I'm writing VERY simple documents and the code is complete and
tested on Word/Excel 2003.

My guess was that i'd need to reference the oldest version we are going
to support, which is Office 2000

thanks
mike
 

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