Solved

COM problems with MS Word

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB.NET 2008 Winforms Signing 13 30
Help with opening combobox using VB.NET. 3 25
Optimize the query 5 42
run a stored procedure from vb.net 1 27
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…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

792 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