Need help developing a COM Add-in for Word(Office XP)
Hi all,
I created a "Shared Add-in" project in Visual Studio .NET 2005 and tried to develop a simple hello world COM add-in for Word.
After created the project, it automatically generated another setup project and this is good. Then I added a reference to the Word Interop Assembly in the Add-in project and confirmed that the DLL file actually references to assembly in windows\assembly folder. Since I just want to make sure that Word can connect to this COM Add-in, I simply added a statement MsgBox("hello world.") to every event that appears in the default Connect class. Then I built both the add-in project and the setup project and right-clicked on the setup project and selected "Install" to install the add-in.
After the installation was finished, I opened Word and clicked the COM Add-in button but I only saw COM Add-ins of other programs there and could not see the COM Add-in I just developed.
So would anybody please suggest what are the things that I can check to figure out what I did wrong?
Thanks a lot.
[1239 byte] By [
motorola] at [2007-12-30]
COM add-ins can be registered for all users (HKEY_LOCAL_MACHINE) or current user (HKEY_CURRENT_USER) and I don't know about Word, but its cousin Outlook only shows in the COM-Addins dialog one of the types (current user), not the other.
If you tell the wizard that you want it for the current user and when running the setup you select current user too, it appears in the COM add-ins dialog, I have just tested it.
Nonetheless, an all-users add-in should be loaded even if it does not appear in the COM addins dialog if it was configured to load on startup (LoadBehavior=3 registry entry).
Carlos Quintero MVP wrote: |
| COM add-ins can be registered for all users (HKEY_LOCAL_MACHINE) or current user (HKEY_CURRENT_USER) and I don't know about Word, but its cousin Outlook only shows in the COM-Addins dialog one of the types (current user), not the other. If you tell the wizard that you want it for the current user and when running the setup you select current user too, it appears in the COM add-ins dialog, I have just tested it. Nonetheless, an all-users add-in should be loaded even if it does not appear in the COM addins dialog if it was configured to load on startup (LoadBehavior=3 registry entry). |
|
Hi MVP,
Thank you very much for your reply.
I have tried, no matter whether this option was checked or not:
"My Add-in should be available to all users of the computer it was installed on, not just the person who installs it."
My "MyAddIn1" still could be not found in the "COM Add-in manager" of Word.
And of course, I didn't get any "Hello World" messages when starting or closing Word.
But I did have the option "I would like my Add-in to load when the host application loads." checked so this is quite strange.
I also examined the registry entry that located in "HKEY_CURRENT_USER\Software\Microsoft\Office\Word\Addins\MyAddin1.Connect" and confirmed that it contains "LoadBehavior=3"
Since I don't want to give up so I used the "Add-in Wizard" to create another "Shared Add-in" again but this time I not only checked "Microsoft Word" but also "Microsoft Powerpoint" in the page that allows me to select host applications. And I also checked ONLY this option:
"I would like my Add-in to load when the host application loads."
and left this option unchecked:
"My Add-in should be available to all users of the computer it was installed on, not just the person who installs it."
Then I built both the "Add-in project" and the "Setup project" as usual. And first I started Word and the situation remained no change, I still could not get the "Hello World" message box and also I still could not see my Add-in listed in the COM Add-in manager.
So I closed Word and then started Powerpoint and I finally saw the "Hello World" message boxes.
Then I examined the "COM Add-in manager" in Powerpoint but I still could not see my Add-in listed there.
When I closed Powerpoint there were still "Hello World" message boxes popping up.
This proves my Add-in can communicate with Powerpoint but not Word.
I don't know why my Add-in did not appear in the "COM Add-in manager" of both Word and Powerpoint but this doesn't really matter.
I just want my Add-in to work in Word and I have Office XP SP3 installed so I guess this shouldn't be a bug.
I also had the "Macro security level" turned to LOW for both Word and Powerpoint already.
So would you please give me some suggestion on what I can do to get it work?
Thank you very much. 
I tested with Visual Studio 2005 and Office 2003, not sure if Office XP makes a difference.
Some things that you can test:
1) In the About window of Word, button Disabled Items, ensure that your add-in has not been disabled.
2) Use the regmon (http://www.sysinternals.com/Utilities/Regmon.html) to monitor the registry activity of word regarding add-ins.
Carlos Quintero MVP wrote: |
| I tested with Visual Studio 2005 and Office 2003, not sure if Office XP makes a difference. Some things that you can test: 1) In the About window of Word, button Disabled Items, ensure that your add-in has not been disabled. 2) Use the regmon (http://www.sysinternals.com/Utilities/Regmon.html) to monitor the registry activity of word regarding add-ins. |
|
Thanks MVP,
Thank you VERY VERY much for helping me.
I opened Word and examined the Disabled Items and found no add-in was disabled.
Then I use regmon to monitor the registry activity when Word is starting. I tried several times and I started to notice that the "LoadBehavior" of my add-in was set to 2(originally it was 3) by Word and this did not happen for other add-ins that had been already installed before.
So what could be the possible cause of Word automatically setting the "LoadBehavior" of my add-in to 2 when starting?
Thanks again. 
Everytime I started word, it always reset the value of LoadBehavior to 2.
After searching in google and yahoo, I discovered that this problem might be due to not referencing a correct office.dll.
So I checked if the add-in project is referencing the office.dll which is located the windows\assembly folder and the answer is yes.
Some people also say that if there is an exception in the OnConncecion event, this behavior will occur. However, there is only one Msgbox("Hello World") statement in the OnConnection event so this possibility is also ruled out.
I also tried to disable the Norton Anti-Virus when running Word to ensure that it does not interfere with the add-in but it still didn't solve the problem.
Would you mind giving me some other suggestions on what I can check?
It's difficult to say, so we will use another approach, we are going to build a minimal Word add-in that works and then you compare it with yours, or you add things until it breaks. So:
- Open VS 2005, create a new VB.NET shared add-in, select Word as host.
- In the page 4 of 5, check the "I would like my add-in to load when the host application loads"
- In the page 4 of 5, do NOT check the "My add-in should be available to all users..."
- Add a reference and an Imports to System.Windows.Forms
- In the Connect.vb class, put this code (note: you should always use exception handlers):
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 Try
MessageBox.Show("Add-in loaded")
Catch ex As Exception
MessageBox.Show(ex.ToString)
End TryEnd Sub- Save the changes and build the setup project.
- Install the setup project. Select the radio button "Just for me" instead of "Everyone"
- Open Word. The add-in should be loaded and you should see the "Add-in loaded" messagebox.
- Go to Tools, COM Add-ins menu. The add-in should appear in the list, checked.
Carlos Quintero MVP wrote: |
| It's difficult to say, so we will use another approach, we are going to build a minimal Word add-in that works and then you compare it with yours, or you add things until it breaks. So: - Open VS 2005, create a new VB.NET shared add-in, select Word as host. - In the page 4 of 5, check the "I would like my add-in to load when the host application loads" - In the page 4 of 5, do NOT check the "My add-in should be available to all users..." - Add a reference and an Imports to System.Windows.Forms - In the Connect.vb class, put this code (note: you should always use exception handlers): 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 Try MessageBox.Show("Add-in loaded") Catch ex As Exception MessageBox.Show(ex.ToString) End TryEnd Sub- Save the changes and build the setup project. - Install the setup project. Select the radio button "Just for me" instead of "Everyone" - Open Word. The add-in should be loaded and you should see the "Add-in loaded" messagebox. - Go to Tools, COM Add-ins menu. The add-in should appear in the list, checked. |
|
Hi MVP,
I followed your steps very carefully but it still produced the same behavior (everytime the Word starts, it resets the LoadBehavior value to 2, if I change it back to 3 using regedit and then start word again, it again resets it to 2.)
Of course, I did't get the "Add-in loaded" message box nor did I see my add-in in the list of "COM Add-ins" of Word.
I did NOT choose "My add-in should be available to all users..."
and I DID choose "Just for me" radio button (actually it is chosen by default) during the add-in installation.
I read this article before: http://support.microsoft.com/kb/316723/
so I know if my add-in is created for all users on my machine, it will NOT appear in the "COM Add-ins" list.
I have no idea why it does not appear in the "COM Add-ins" list.
There must be some conflicts and I agree this is really hard to figure out what is going wrong.
Thanks again MVP. You helped me a lot. 
Is there any chance of testing your setup and your add-in on a different machine:
1) With Word 2002 (XP). If it works, then there is something specific to your machine, not Word 2002
2) With Word 2003 instead of Word 2002 (XP)? If it works, then the problem is Word 2002 vs Word 2003.
It could be also a security setting, but I am not sure.
Carlos Quintero MVP wrote: |
| Is there any chance of testing your setup and your add-in on a different machine: 1) With Word 2002 (XP). If it works, then there is something specific to your machine, not Word 2002 2) With Word 2003 instead of Word 2002 (XP)? If it works, then the problem is Word 2002 vs Word 2003. It could be also a security setting, but I am not sure. |
|
Hi MVP,
Yes, I will try it on another machine tomorrow.
Thank you very very much MVP. 
Hi MVP,
I just followed your steps once again using VS.NET 2003(I have both 03 and 05 installed on my machine but I have been testing using 05) and the message box finally showed up and I could also see the add-in in the "COM add-ins" of Word. It's great!
Both VS.NET 03 and 05 have the Add-in wizard and they are very similar but I notice something that may be the clue of why the add-in that I built using 05 doesn't work. The add-in and setup project generated by 05 references office.dll using this path: C:\WINDOWS\assembly\GAC\Office\7.0.3300.0__b03f5f7f11d50a3a\Office.dll
Whereas the add-in and setup project generated by 03 references office.dll using this path:
C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\Office.dll
What do you think? 
I don't think that Office.dll is the cause. That dll is only needed for the commandbars and in fact for the small sample that we are talking about you can remove that reference and the add-in will compile fine.
Word add-ins created with VS 2005 work fine on my machine so you really need to test with Word 2003 and / or use another machine.
While creating add-ins with VS.NET 2003 for Office is possible, there are some problems with the COM Interop, specially with Outlook, that where not solved completely until VS 2005.
FWIW, there are several references to create managed add-ins for Office XP and Office 2003 on my web site:
http://www.mztools.com/resources_office_addins.htm
Maybe some of them can help.
Hi MVP,
Yes, office.dll is not the cause.
Maybe I will do some testing and report back later.
By the way, your website is great!I like it.
Thank you very very much for your help so far. 
I really have to thank YOU, motorola.
I ran into the same problem as yours when developing a COM Add-in with VS 2005. The only difference is that my host application is Outlook.
I read your discussion with MVP very carefully and it is very fortunate for me that I read it through to the end and found your final solution. I applied your final solution and BINGO! I got it right!
The problem had been puzzling me for quite a few days so I really wanna thank you and MVP. Thank you very much!