Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / January 2005

Tip: Looking for answers? Try searching our database.

Problems with Word 2000 automation

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
BarbourIndex - 05 Jan 2005 09:26 GMT
Hi

I'm automating Word in my VB.NET Windows Forms application, and I'm hitting
a problem when the application is used with Word 2000.

To access the Word functionality, I created a reference to the Word 97 type
library (we support all versions from 97 onwards). I then have some code
that creates a new Word document, puts some text into it and then calls the
SaveAs method of the document object to save the document with a given
filename. A cutdown version of the code is here - basically I have removed
the majority of the text insertion stuff for clarity...

Dim strFilename as String = "C:\MyTest.doc"

Dim WordApp as New Word.Application
Dim WordDoc as Word.Document = WordApp.Documents.Add()

WordDoc.Range.InsertAfter("Some text")

WordDoc.SaveAs(CObj(strFilename))
WordApp.Quit()

This works fine on the majority of machines, including my development
machine (Word 2002 SP1 on Win2k). However the SaveAs fails when run on a
machine running Word 2000 SR1. The error reported is that an object
reference is not set to an instance of an object.

The confusing thing is that I have done this previously in C++, and it works
fine on the very same machine. I have checked that the document object is
set to a valid instance, and it is, so I'm guessing the problem lies in one
of the parameters. All the parameters other than the filename however are
optional, and are left blank.

In the C++ code, the optional parameters have to be supplied, so I pass
variants, with the type set to VT_ERROR and the value set to
DISP_E_PARAMNOTFOUND. I did wonder if the optional parameters that I had
omitted in VB.NET were being treated differently, so I wrote an automation
server app with a method that had optional parameters, to see what was
passed. VB.NET passes a variant exactly the same as I have to in the C++
code - type VT_ERROR and value DISP_E_PARAMNOTFOUND.

So, I'm a little confused as to what is going on. Any ideas would be most
welcome, as Google has failed me!

Best regards

Martyn Pearson
Barbour Index
"Peter Huang" [MSFT] - 06 Jan 2005 02:41 GMT
Hi,

In C++ or vb(unmanaged), if we wants to automation a COM object(word
application), we just need to call the COM object directly.

While in managed code, i.e. .NET, we need to use a interop assembly which
is a wrap of the COM object, so when we call word application COM object
modal, what we do is as follows, .NET ---> Interop Assembly---> COM Object.

From Office XP, we provide official Primary Interop Assembly(PIA), we can
get it in the link below.
Office XP PIAs
http://www.microsoft.com/downloads/details.aspx?FamilyId=C41BD61E-3060-4F71-
A6B4-01FEBA508E52&displaylang=en

Also office 2003 has its PIA but it is different from the Office XP one, we
can not replace with each other. Office 2003 PIA is shipped with office
2003 installation package, we can not deploy it independently.

So for your scenario, I think we have to build a PIA for every version.
Here are some links you may take a look.
http://groups.google.co.jp/groups?hl=zh-CN&lr=&threadm=75A203E0-D419-4AF5-82
C5-BFCBBD6F04AF%40microsoft.com&rnum=1&prev=/groups%3Fq%3D%2522peter%2BHuang
%2522%2Bdave%2Bword%2B2000%2BPIA%26hl%3Dzh-CN

http://groups.google.co.jp/groups?hl=zh-CN&lr=&threadm=1B9454BD-0E51-48FC-8E
E4-71D086A09B75%40microsoft.com&rnum=3&prev=/groups%3Fq%3D%2522peter%2BHuang
%2522%2Bdave%2Bword%2B2000%2BPIA%26hl%3Dzh-CN

Primary Interop Assemblies
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/ht
ml/whypriinterop.asp

Best regards,

Perter Huang
Microsoft Online Partner Support

Signature

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.