Solved

COM problems with MS Word

Posted on 2004-08-20
4
258 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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

746 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now