Solved

COM problems with MS Word

Posted on 2004-08-20
4
271 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

726 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