Solved

COM problems with MS Word

Posted on 2004-08-20
4
266 Views
Last Modified: 2010-04-23
I wanted to build a VB.NET class file which would replace words in a Word Document. Now, the unique thing about it is I guess it is COM, meaning I have to strong name it.

After many problems with trying to strong name the reference to Word.Interop, I found this documentation:

http://support.microsoft.com/?kbid=313666

I followed the VB.NET instructions to the tee, and it worked. I thought it was clear sailing from there...apparently not. The new reference I added was MyWord.dll which was the result of the documentation. I then declared it with the following:

Dim ThisApplication As MyWord.Application // to replace the regular Word.Application instance

Ok still going good...VS.NET recognizes all objects, methods, and properties of the regular MS Word Libs with MyWord.dll

Next, I take the project, put it onto a different computer, and register all the typelibs via regasm and then the assembly with gacutil.

Working good for like:

Dim my_text As String

Public Property mytext()
Get
Return my_text
End Get
Set(ByVal Value)
my_text = Value
End Set
End Property

But as soon as I call this function via COM from my other application:

Public Sub SearchReplace()
ThisApplication.Documents.Open("C:\test.doc")
End Sub

Everything stops with this error:

File or assembly name MyWord, or one of its dependencies, was not found.

Now I know that the Documents.Open() method exists, because my VS.NET sees it in object viewer. Could it be that I'm developing on 1 computer and then trying to make it work with another computer (I've registered and gac'ed on both computers).

Thanks in advance.
0
Comment
Question by:drakkarnoir
  • 3
4 Comments
 
LVL 4

Accepted Solution

by:
Daniellus83 earned 500 total points
ID: 11855239
I had some trouble too,.. Are you sure all needed .dll are on the pther (non developing) system?

I used this commando's to register my assemblies:

gacutil /if myfile.dll
regasm myfile.dll

But in order to have these tools function fully I needed on the 'other' machine (.Net Framework v1.1 installed) the following files:

advapi32.dll
kernel32.dll
mscoree.dll
msvcr71.dll  <<
shlwapi.dll
user32.dll

Maybe it solves your problem... It is tricky to get this working, there are linkers on the market; they solve all these dependencies by adding all these used .net references (system.io ..etc) to your assembly: (http://www.remotesoft.com/linker/ is an example)

Hopes it helps you a bit... Daniël

-----
BTW: there are many ppl asking questions about strong naming. It is quite easy with the free tool Deadbolt.Net. You can find it here:

     https://secure.interscapeusa.com/Register/Downloads.aspx?Authenticated=True

> After install you create your own token (key) via tools>deadbolt.net>create... (vs.net2003).
> To digitally sign (strong name) your project, right-click on the Assembly.vb file in your project and choose "Digitally sign"

This tools saves you lot of time in the future signing your things


0
 
LVL 4

Expert Comment

by:Daniellus83
ID: 11855253
forgot: try resigning your assembly (with the tool) ...you never know....
0
 

Author Comment

by:drakkarnoir
ID: 11856190
I figured it out...it required me to register MyWord.dll via gacutil...

gacutil /i MyWord.dll

Now that message is gone, but I have another error:

Object reference not set to an instance of an object.

This happens when I reference any object or method.
0
 
LVL 4

Expert Comment

by:Daniellus83
ID: 11857927
Hello,..  I am happy the problem was solved easy...

The other thins "...Object reference not set to an instance of an object.."

Mostly this occurs when you do this:

   'Define it
   Dim i as Formtest

   'Use it (within a button_click or something...)
   Formtest.show

In some cases (classes..) you need to define (like this one)

dim i as Formtest = new formtest  'So the New() function inside gets called

If you define a var as string (Dim a as string) you don't use it...

So try this NEW thing... Else the object is still "Nothing" and then you get this error.

0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question