.NET automation version problem

P

ppp01

Hi,

1. Could I automate Office 97 with .Net C# ?

2. If I just want to automate the Word version from Word2000, Word XP to
Word 2003,
which one of the following methods is the best for integrating multiple
version automation in a single
application by .Net ?
i. By late binding ?
ii. By early binding, but we have individual modules for each version of
Word, and the application can
detect the version of the Word in the client system, and then load the
appropriate version module ?
iii. Any other third method ?

Thanks so much
 
J

Jonathan West

ppp01 said:
Hi,

1. Could I automate Office 97 with .Net C# ?

In principle yes. Word 97 can be controlled through COM interop. Hook up to
the Word.Application object and the whole of the Word object model becomes
available to you
2. If I just want to automate the Word version from Word2000, Word XP to
Word 2003,
which one of the following methods is the best for integrating multiple
version automation in a single
application by .Net ?
i. By late binding ?

This can certainly be made to work. The following example is a VBA example
but will show you the principles which you can apply to C#

Control Word from Excel
http://www.word.mvps.org/FAQs/InterDev/ControlWordFromXL.htm

ii. By early binding, but we have individual modules for each version of
Word, and the application can
detect the version of the Word in the client system, and then load the
appropriate version module ?

With early binding you would have to develop against and set references to
the earliest version of Word that you want to be compatible with. Then the
later versions should also word. You can always branch into different code
areas by checking the Version property of the Word application object.
iii. Any other third method ?

I'm not aware of a third method.

Which of the first two methods is "better" depends on your criteria, and
that depends on exactly what you want to do. I think I would be inclined to
go for early binding as that is generally a bit quicker, and move to late
binding if there you discover a major gotcha that you can't get around with
early binding.

--
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
 
P

ppp01

Hi Jonathan,

Thanks for your reply. But I still have some questions as follows,

1. As you have stated, by using early binding and pointing to the references
of the earliest Word version in the PC during developing. And If the earlier
version of Word is Word 2000, what Word dll version should I refer to ?
But for a pc with word 2003, it shouldn't have the word dll for word2000, so
how can it run ?

2. Do you think it is more appropriate to adopt VB.Net or C#.Net for Word
automation,
coz when I do automation programming in C#.Net, I found that the method
arguments
consists of many missing values ?

Thanks very much


"Jonathan West" 來函:
 
J

Jonathan West

ppp01 said:
Hi Jonathan,

Thanks for your reply. But I still have some questions as follows,

1. As you have stated, by using early binding and pointing to the
references
of the earliest Word version in the PC during developing. And If the
earlier
version of Word is Word 2000, what Word dll version should I refer to ?
But for a pc with word 2003, it shouldn't have the word dll for word2000,
so
how can it run ?

The reference should associate itself with the library "Word" rather than
the filename of the specific DLL which holds it. Therefore, for later
versions of Office, even though the DLL has a different name and is located
in a different folder, the reference should still work.

I know it works from VB6. I am not familiar with C#, but since we are
dealing with COM early binding in both cases, I see no reason why things
should be any different. However, the simplest thing to do is to create a
minimal application that does little except bind to Word, and test it on
different machines with different versions of Office installed.
2. Do you think it is more appropriate to adopt VB.Net or C#.Net for Word
automation,
coz when I do automation programming in C#.Net, I found that the method
arguments
consists of many missing values ?

This is a question for which there is no hard & fast answer. It depends your
familiarity with the two languages and how much of your application is going
to be involved in controlling Word.

All other things being equal, I suggest you use VB.NET in preference to C#,
because VB.NET is more similar to VBA. The Word VBA Help files are therefore
more likely to be meaningful and the code samples easier to adapt when
needed.


--
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
 

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