word 2003 com add-in vs2003

R

Ratnesh Raval

hi all,
i am writing word 2003 com add-in using visual studio 2003 vb.net. i m very
new to word or any add-in. so i m very confused.

1. i created a shared add-in using the article
http://support.microsoft.com/default.aspx?scid=kb;en-us;302901 . first i was
not able to debug it, but excluding office.dll from setup project did the
trick. and now if i include it again i m still able to debug it. its good
but can anyone throw some light.

2 also, in many articles and posts discuss PIAs , i m not sure why its
needed in here. coz creatig default add-in project doesnt need any.

3. the default project uses application as object. so i m not able to use
properties/methos/etc of word. can anyone show how can u change it
Public Sub OnConnection(ByVal application As Object, ByVal connectMode
As Extensibility.ext_ConnectMode, ByVal addInInst As Object, ByRef custom
As System.Array) Implements Extensibility.IDTExtensibility2.OnConnection
applicationObject = application
addInInstance = addInInst
' If you aren't in startup, manually call OnStartupComplete.
If (connectMode <> Extensibility.ext_ConnectMode.ext_cm_Startup)
Then _
Call OnStartupComplete(custom)
End Sub
also links to some startup articles and help will be appriciated. more
confusions on shim and some other things later on....

thnx
 
C

Cindy M -WordMVP-

Hi Ratnesh,
2 also, in many articles and posts discuss PIAs , i m not sure why its
needed in here. coz creatig default add-in project doesnt need any.
How do you know it doesn't need any? Because you're certain none are
installed? If you installed Office 2003 after the .NET Framework 1.1 was
installed on your machine, the PIAs were put into the GAC automatically.

In any case: as soon as you set a reference to a COM object, Visual Studio
will generate a set of IAs in your project's folder to enable communication
with the COM library. So, yes, one can get along without PIAs. But if they're
available they should be used because the creator (Microsoft, in this case)
will have taken care to optimize the .NET said:
3. the default project uses application as object. so i m not able to use
properties/methos/etc of word. can anyone show how can u change it
Public Sub OnConnection(ByVal application As Object, ByVal connectMode
As Extensibility.ext_ConnectMode, ByVal addInInst As Object, ByRef custom
As System.Array) Implements Extensibility.IDTExtensibility2.OnConnection
applicationObject = application
addInInstance = addInInst
' If you aren't in startup, manually call OnStartupComplete.
If (connectMode <> Extensibility.ext_ConnectMode.ext_cm_Startup)
Then _
Call OnStartupComplete(custom)
End Sub
you need to declare your own variable, then "cast" the one passed by
OnConnection to yours. I usually do this in C#, so no guarantees I'll get
this exactly right, but something like this:
Dim wdApp As Word.Application
wdApp = CType(application, Word.Application)


Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :)
 
F

Fritz_With_MS

Not to seem that I'm picking on just you, many, many people are guilty, too,
but I can't stand the fact that you fail severely when it comes to
punctuation & capitalizationIn my opinion, this is blantant laziness! Would
you write this way when writing a 'real,' printed letter? I should hope not!

- FL
________________________________________________
 
R

Ratnesh Raval

Hi Cindy,
How do you know it doesn't need any? Because you're certain none are
installed? If you installed Office 2003 after the .NET Framework 1.1 was
installed on your machine, the PIAs were put into the GAC automatically.

when i create a new project for shared add-in, it has only reference to
C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\Office.dll
which is not in the GAC folder. though i have PIAs installed.

I dont have any referance added to word or microsoft.office.interop
so i added a reference to word which uses the PIAs from GAC.

but having both 'office.core' and 'office.interop' references created
another problem and i m getting 'System.ExecutionEngineException'

Also, i've another problem. when i click on the button created by my
project. word shows following message "the macro cannot be found or has been
disabled because of your macro security settings". my macro security
settings are 'medium', i've checked to trust installed and visual studio
addins , and i dont have any disabled items.

thnx for the help
 
C

Cindy M -WordMVP-

Hi Ratnesh,
when i create a new project for shared add-in, it has only reference to
C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\Office.dll
which is not in the GAC folder. though i have PIAs installed.
I no longer have VS2003 installed, so what I see may well not parallel what you
have, however...

By default, on my machine the shared Addin creates a reference to
Microsoft.Office.Core, the office.dll in the GAC. In the Setup project, there's
a reference to office.dll but it's disabled. This would be correct because your
Addin project shouldn't be trying to install a PIA that ought to be present on
the target machine. If you were creating an Add-in that might target Office
2000 or 97, you'd need a set of IAs you create. In this case, you would need to
distribute them with your project, meaning you'd need to change this
dependency.
I dont have any referance added to word or microsoft.office.interop
so i added a reference to word which uses the PIAs from GAC.
This is correct. For the applications you intend to target with your Add-in,
unless you plan to use late-binding, you need to Add the References from the
COM tab in the References dialog box.
but having both 'office.core' and 'office.interop' references created
another problem and i m getting 'System.ExecutionEngineException'
You shouldn't need to add a reference to office.interop?
Also, i've another problem. when i click on the button created by my
project. word shows following message "the macro cannot be found or has been
disabled because of your macro security settings". my macro security
settings are 'medium', i've checked to trust installed and visual studio
addins , and i dont have any disabled items.
This is on your development machine, while in debug mode?

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :)
 
R

Ratnesh Raval

Hi Cindy,
By default, on my machine the shared Addin creates a reference to
Microsoft.Office.Core, the office.dll in the GAC. In the Setup project,
there's
a reference to office.dll but it's disabled. This would be correct because
your
Addin project shouldn't be trying to install a PIA that ought to be
present on
the target machine. If you were creating an Add-in that might target
Office
2000 or 97, you'd need a set of IAs you create. In this case, you would
need to
distribute them with your project, meaning you'd need to change this
dependency.

In 2003, the default project didnt refer to GAC, i corrected that.
You shouldn't need to add a reference to office.interop?

now after adding reference to word, it adds reference to
Microsoft.office.interop.word
and the project already has Microsoft.office.core
now using following statement
dim AppObj as Microsoft.office.interop.word.application
started giving me error ( Reference required to assembly 'office' containing
the type 'Microsoft.Office.Core.CommandBars'. Add one to your project.) in
the following statement
oCommandBars = AppObj.CommandBars
This is on your development machine, while in debug mode?

Yes, i also tried in Release mode too, but no luck.

Thanks
 
C

Cindy M -WordMVP-

Hi Ratnesh,
now after adding reference to word, it adds reference to
Microsoft.office.interop.word
and the project already has Microsoft.office.core
now using following statement
dim AppObj as Microsoft.office.interop.word.application
started giving me error ( Reference required to assembly 'office' containing
the type 'Microsoft.Office.Core.CommandBars'. Add one to your project.) in
the following statement
oCommandBars = AppObj.CommandBars
Show me all the using (if this is C#; Imports if this is VB) statements at the
top of your class, please.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :)
 
R

Ratnesh Raval

Hey Cindy,
Show me all the using (if this is C#; Imports if this is VB) statements at
the
top of your class, please.

i was able to solve that problem, i had to reinstall/repair office
installation.

but still the following problem remains
This is on your development machine, while in debug mode?

Yes, i also tried in Release mode too, but no luck.

Thnx
 
C

Cindy M -WordMVP-

Hi Ratnesh,
but still the following problem remains

Yes, i also tried in Release mode too, but no luck.
Please start a new message thread for this, as I'm not sure of the answer.
This will give it the best exposure so that others may see and give their
ideas.

Be sure to give the version of Word (so that it's clear in that thread), the
programming language you're using, and copy in the code that creates the
button, assigns the Click event, and the event code.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :)
 
R

Ratnesh Raval

Thanks Cindy,

As you told i've created a new topic for the problem. but i;ve got one more
problem to ask.

When exiting word app. i m deleting the button, but somehow its not getting
deleted.
here is my code, also check the commented lines. i've tried that way too.
but no luck, the button is still there

Public Sub OnBeginShutdown(ByRef custom As System.Array) Implements
Extensibility.IDTExtensibility2.OnBeginShutdown
'myButton.Delete()
'oStandardBar.Controls.Item(myButtonIndex).Delete()
oCommandBars.FindControl(, , "Custom Merge Field").Delete()
Marshal.ReleaseComObject(myButton)
myButton = Nothing
oStandardBar = Nothing
oCommandBars = Nothing
End Sub
 
C

Cindy M -WordMVP-

Hi Ratnesh,
As you told i've created a new topic for the problem. but i;ve got one more
problem to ask.
Correctly, this should have been posted as yet another topic...

However, after scanning the code in your separate posting (about the addin not
loading) I notice you don't set the CustomizationContext. This is something
you need only in Word because Word can save a CommandBar's settings in:
- NormalTemplate (Normal.dot)
- ActiveDocument (the current document)
- AttachedTemplate (the template attached to a document object)
- any other member of the Templates collection

So, if you just start making changes to CommandBars without specifying where
these changes should be saved (CustomizationContext) they could theoretically
end up "anywhere". And when you later go to change or delete them, you can't
"grab" them propery.

You need to set CustomizationContext in every procedure where you manipulate
CommandBars.
When exiting word app. i m deleting the button, but somehow its not getting
deleted.
here is my code, also check the commented lines. i've tried that way too.
but no luck, the button is still there

Public Sub OnBeginShutdown(ByRef custom As System.Array) Implements
Extensibility.IDTExtensibility2.OnBeginShutdown
'myButton.Delete()
'oStandardBar.Controls.Item(myButtonIndex).Delete()
oCommandBars.FindControl(, , "Custom Merge Field").Delete()
Marshal.ReleaseComObject(myButton)
myButton = Nothing
oStandardBar = Nothing
oCommandBars = Nothing
End Sub

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :)
 

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