Calling Add-in methos in VBA for Word XP

C

Cameron

I am having a problem with calling a method of my COM add-in from VB
in Word XP. The Add-in has been developed using ATL/MFC.

Here is what I'm doing.

Dim addIn As Object
Set addIn = Application.COMAddIns.Item("MyAddin")
MsgBox addIn.ProgID
addIn.Object.MyFunction ("Hello")

The call to addIn.ProgID works correctly, however the call to
addIn.Object.MyFunction causes a Run time error 91 'Object variable or
With block variable not set'. I have also tried to do

Dim addIn As Object
Set addIn = Application.COMAddIns.Item("MyAddin").Object
addIn.MyFunction ("Hello")

This does not work either. If I use the OLE viewer I can see the
function in the type libary. Can anyone help? Also is there an
example of such a add-in? I know of the example by Amit Dey, however
I am having problems getting this to compile under VS.NET 2003.

Cheers

Cameron
 
T

Tom Winter

Cameron said:
I am having a problem with calling a method of my COM add-in from VB
in Word XP. The Add-in has been developed using ATL/MFC.

Here is what I'm doing.

Dim addIn As Object
Set addIn = Application.COMAddIns.Item("MyAddin")
MsgBox addIn.ProgID
addIn.Object.MyFunction ("Hello")

The call to addIn.ProgID works correctly, however the call to
addIn.Object.MyFunction causes a Run time error 91 'Object variable or
With block variable not set'. I have also tried to do

Dim addIn As Object
Set addIn = Application.COMAddIns.Item("MyAddin").Object
addIn.MyFunction ("Hello")

This does not work either. If I use the OLE viewer I can see the
function in the type libary. Can anyone help? Also is there an
example of such a add-in? I know of the example by Amit Dey, however
I am having problems getting this to compile under VS.NET 2003.

Cheers

Cameron

Generally speaking, I have found that the Object property of the COMAddIn
object does not work. At least I could not get it to work reliably way back
when I wanted to with Word 2000. Other people may have had better
experiences. Comments?

You might want to try a different approach. Put a creatable (or global)
class in your COM Add-In that VB can create and then call. It might just be
a helper object that returns the running instance of your COM Add-In object.
Let me know if you need more explanation.

-Tom
 
D

dotnet-force

Hi,

Tom said:
Generally speaking, I have found that the Object property of the COMAddIn
object does not work. At least I could not get it to work reliably way back
when I wanted to with Word 2000. Other people may have had better
experiences. Comments?

You might want to try a different approach. Put a creatable (or global)
class in your COM Add-In that VB can create and then call. It might just be
a helper object that returns the running instance of your COM Add-In object.
Let me know if you need more explanation.

-Tom

I had the same experience and use the solution of the global object in
my Add-In.

As I have to access to my Add-In in a JavaScript function (it's an
Add-In for MS Project), I need to create this object as follow :
var object = new ActiveXObject("MyObject");

But once this code is executed, I have the following message :
An ActiveX control on this page might be unsafe to interact
with other parts of the page. Do you want to allow this
interaction?
Yes No

Then I click Yes and the object is correctly created.
How can I remove this message on my machine ?
And what to do if I want to install my Add-In on othe machine ?

Is it a question of Certificate ?

Pascal Lenormand
ILOG
 
T

Tom Winter

dotnet-force said:
Hi,



I had the same experience and use the solution of the global object in
my Add-In.

As I have to access to my Add-In in a JavaScript function (it's an
Add-In for MS Project), I need to create this object as follow :
var object = new ActiveXObject("MyObject");

But once this code is executed, I have the following message :
An ActiveX control on this page might be unsafe to interact
with other parts of the page. Do you want to allow this
interaction?
Yes No

Then I click Yes and the object is correctly created.
How can I remove this message on my machine ?
And what to do if I want to install my Add-In on othe machine ?

Is it a question of Certificate ?

Pascal Lenormand
ILOG

Sorry, but I don't know anything about this type of stuff with JavaScript
and ActiveX controls, but I imagine you are correct that you'll need some
sort of digital certificate for it. Search MSDN and MS's Knowledge Base for
that type of stuff. Or ask in one of the JavaScript newsgroups.

-Tom
 
S

Stephen Bullen

Hi Tom,
Generally speaking, I have found that the Object property of the COMAddIn
object does not work. At least I could not get it to work reliably way back
when I wanted to with Word 2000. Other people may have had better
experiences. Comments?

Sorry it's a bit late, but I found that in VB, adding the line:

AddinInst.Object = Me

in the OnConnection event links it all up fine (note the lack of a 'Set')

Regards

Stephen Bullen
Microsoft MVP - Excel
www.BMSLtd.co.uk
 
C

Cameron

Tom Winter said:
Generally speaking, I have found that the Object property of the COMAddIn
object does not work. At least I could not get it to work reliably way back
when I wanted to with Word 2000. Other people may have had better
experiences. Comments?

You might want to try a different approach. Put a creatable (or global)
class in your COM Add-In that VB can create and then call. It might just be
a helper object that returns the running instance of your COM Add-In object.
Let me know if you need more explanation.

-Tom

Tom,

If you could provide some sample code and/or more details on how I
could do this that would be great.

Thanks
 
T

Tom Winter

Cameron said:
"Tom Winter" <[email protected]> wrote in message

Tom,

If you could provide some sample code and/or more details on how I
could do this that would be great.

Thanks

Cameron,

I have written an article about the various options. You can view it here:

http://www.amosfivesix.com/articles/CallableCOMAddIn/

You can download the sample project for the article here:

http://www.amosfivesix.com/downloads/

Note that I put this together really quick, so forgive me if it's not too
detailed. E-mail me if you have any questions!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top