Creating COM add-inn for office application
Creating COM add-inn for office application
Creating COM add-inn for office application
Creating COM add-inn for office application
Creating COM add-inn for office application
Creating COM add-inn for office application Creating COM add-inn for office application Creating COM add-inn for office application Creating COM add-inn for office application Creating COM add-inn for office application Creating COM add-inn for office application Creating COM add-inn for office application Creating COM add-inn for office application
Creating COM add-inn for office application Creating COM add-inn for office application
Creating COM add-inn for office application
Go Back  Xtreme Visual Basic Talk > > > Creating COM add-inn for office application


Reply
 
Thread Tools Display Modes
  #1  
Old 09-30-2007, 04:04 AM
Alex30 Alex30 is offline
Regular
 
Join Date: Sep 2007
Posts: 51
Unhappy Creating COM add-inn for office application


Hello,
I am Alex and I am new to this forum.

After endless desperate attempts to create COM add-inn for office application, I gave up and decided to ask for help of others.

In order to create COM add-inn I followed the MSDN article: http://support.microsoft.com/kb/302896

But it just doesn't work.

I am sure that I am missing some small but important detail.

Thanks in advance for any help.

Alex.
Reply With Quote
  #2  
Old 09-30-2007, 05:34 AM
DennisW's Avatar
DennisW DennisW is offline
Junior Contributor
 
Join Date: Mar 2006
Location: Östersund, Sweden
Posts: 268
Default

Alex,

Welcome to the forum

Quote:
But it just doesn't work.
You need to explain in more details what does not work and what kind of error messages You get.
__________________
Kind regards,
Dennis

.NET & Excel | 2nd edition PED | MVP
Reply With Quote
  #3  
Old 09-30-2007, 01:23 PM
Alex30 Alex30 is offline
Regular
 
Join Date: Sep 2007
Posts: 51
Default

I perform instruction from MSDN tutorial, step by step. After “building” the add-in, I open Word or Excel, but nothing happens.
I couldn’t find the add-in through COM Add-Ins menu in Word. May be there is some problem with dll registration?

Few notes:
1. I don’t have PIAs installed on PC, since I don’t want to be tied to specific version of Office.
2. Every time I start any office application, I get pop up window asking to install some features for Visual Studio 2005 ENU. The installation and configuration process lasts about 30 minutes, but this pop up window appears again and again.
3. I have XP SP2, Office 2003, VS .NET 2005 (all SW original).
4. The same problems appear on two different PCs.
Reply With Quote
  #4  
Old 09-30-2007, 04:23 PM
Alex30 Alex30 is offline
Regular
 
Join Date: Sep 2007
Posts: 51
Default update

Today I found some example that creates COM add-inn for Power Point:
http://msdn.microsoft.com/archive/de...ce03072002.asp
it worked perfect.

But when I tried to make a similar add-id for Word, it didn't work.

Here is the code for Word:

Code:
Imports Microsoft.Office.Core
Imports Extensibility
Imports System.Runtime.InteropServices

' *** BEGIN CUSTOM CODE. ***
Imports Microsoft.Office.Core.MsoControlType
Imports Microsoft.Office.Core.MsoButtonStyle
Imports Microsoft.Office.Core.MsoFileDialogType
Imports Microsoft.Office.Core.MsoFileDialogView
Imports Microsoft.Office.Core.MsoTriState
' *** END CUSTOM CODE. ***


#Region " Read me for Add-in installation and setup information. "
' When run, the Add-in wizard prepared the registry for the Add-in.
' At a later time, if the Add-in becomes unavailable for reasons such as:
'   1) You moved this project to a computer other than which is was originally created on.
'   2) You chose 'Yes' when presented with a message asking if you wish to remove the Add-in.
'   3) Registry corruption.
' you will need to re-register the Add-in by building the $SAFEOBJNAME$Setup project, 
' right click the project in the Solution Explorer, then choose install.
#End Region

<GuidAttribute("3634533B-BA61-4B0E-86AA-343858BE23AC"), ProgIdAttribute("Alex4.Connect")> _
Public Class Connect
	
	Implements Extensibility.IDTExtensibility2

	Dim applicationObject as Object
    Dim addInInstance As Object
    ' *** BEGIN CUSTOM CODE. ***
    Dim WithEvents objCommandBarButton As CommandBarButton
    ' *** END CUSTOM CODE. ***

	
	Public Sub OnBeginShutdown(ByRef custom As System.Array) Implements Extensibility.IDTExtensibility2.OnBeginShutdown
        ' *** BEGIN CUSTOM CODE. ***
        objCommandBarButton.Delete()
        ' *** END CUSTOM CODE. ***

    End Sub
	
	Public Sub OnAddInsUpdate(ByRef custom As System.Array) Implements Extensibility.IDTExtensibility2.OnAddInsUpdate
        ' *** BEGIN CUSTOM CODE. ***
        ' No code needed in this method.
        ' *** END CUSTOM CODE. ***

    End Sub
	
	Public Sub OnStartupComplete(ByRef custom As System.Array) Implements Extensibility.IDTExtensibility2.OnStartupComplete
        ' *** BEGIN CUSTOM CODE. ***
        Dim objCommandBars As CommandBars
        Dim objCommandBar As CommandBar
        Dim objCommandBarControl As CommandBarControl

        ' Create a menu command on the "Tools" menu.
        objCommandBars = applicationObject.CommandBars
        objCommandBar = objCommandBars.Item("Tools")

        ' Make sure menu command doesn't already exist.
        For Each objCommandBarControl In objCommandBar.Controls

            If objCommandBarControl.Caption = "Slides from Graphics..." Then

                objCommandBar.Controls.Item("Slides from Graphics...").Delete()

            End If

        Next objCommandBarControl

        objCommandBarButton = objCommandBar.Controls.Add(msoControlButton)

        With objCommandBarButton
            .Caption = "New Slides from Graphics..."
            .Style = msoButtonCaption
            .Tag = "Slides from Graphics..."
            .OnAction = "!<Alex4.Connect>"
            .Visible = True
        End With
        ' *** END CUSTOM CODE. ***

    End Sub
	
	Public Sub OnDisconnection(ByVal RemoveMode As Extensibility.ext_DisconnectMode, ByRef custom As System.Array) Implements Extensibility.IDTExtensibility2.OnDisconnection
        ' *** BEGIN CUSTOM CODE. ***
        On Error Resume Next

        ' Disconnect the shared add-in, no matter how the host application 
        ' was shut down. 
        If RemoveMode <> Extensibility.ext_DisconnectMode.ext_dm_HostShutdown Then _
           Call OnBeginShutdown(custom)

        applicationObject = Nothing
        ' *** END CUSTOM CODE. ***

    End Sub
	
	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

        ' *** BEGIN CUSTOM CODE. ***
        ' No matter how the host application started, connect the shared add-in.
        If (connectMode <> Extensibility.ext_ConnectMode.ext_cm_Startup) Then _
           Call OnStartupComplete(custom)
        ' *** END CUSTOM CODE. ***

    End Sub

    Private Sub objCommandBarButton_Click(ByVal Ctrl As CommandBarButton, _
            ByRef CancelDefault As Boolean) Handles objCommandBarButton.Click
        MsgBox("Hi")
    End Sub

End Class
Do you have any idea why?
Reply With Quote
  #5  
Old 10-03-2007, 08:49 AM
DennisW's Avatar
DennisW DennisW is offline
Junior Contributor
 
Join Date: Mar 2006
Location: Östersund, Sweden
Posts: 268
Default

Hi Alex,

Quote:
May be there is some problem with dll registration?
Well, if any targeting Office software has issues with loading a managed COM Add-in it get "blacklisted" but

Quote:
I don’t have PIAs installed on PC, since I don’t want to be tied to specific version of Office.
You need to have the required PIAs installed. There are no version neutral PIAs available so You will either to use the offically PIAs from Microsoft or create Your own set of IAs.

Install the required PIAs and let us know the outcome of it.
__________________
Kind regards,
Dennis

.NET & Excel | 2nd edition PED | MVP
Reply With Quote
  #6  
Old 10-03-2007, 06:01 PM
Alex30 Alex30 is offline
Regular
 
Join Date: Sep 2007
Posts: 51
Default

I installed the PIA and tried to make it working on two different PCs, but no results.
Reply With Quote
  #7  
Old 10-04-2007, 02:02 AM
DennisW's Avatar
DennisW DennisW is offline
Junior Contributor
 
Join Date: Mar 2006
Location: Östersund, Sweden
Posts: 268
Default

Alex,

OK - Check first if the add-in has been disabled (blacklisted) by Word. You can check it by choosing the command Help | About Microsoft Excel. In the dialog form click on the button Disabled Items... If the add-in is there then enable it.

I will later check the code you use.
__________________
Kind regards,
Dennis

.NET & Excel | 2nd edition PED | MVP
Reply With Quote
  #8  
Old 10-04-2007, 03:48 AM
Alex30 Alex30 is offline
Regular
 
Join Date: Sep 2007
Posts: 51
Default

Dennis,
Thanks for reply.
I didn’t see the Add-In in “disabled items” menu.
I made the code a bit simpler, it just opens the Message box on startup.

In order to create Add-In, I use “Shared Add-In wizard”.

I check “Word”, “Outlook”, “Excel” and “Power Point” checkboxes.

Add references to all four programs form “Project”  “Add Reference” menu.

Here is the code:
Code:
Imports Microsoft.Office.Core
Imports Extensibility
Imports System.Runtime.InteropServices


#Region " Read me for Add-in installation and setup information. "
' When run, the Add-in wizard prepared the registry for the Add-in.
' At a later time, if the Add-in becomes unavailable for reasons such as:
'   1) You moved this project to a computer other than which is was originally created on.
'   2) You chose 'Yes' when presented with a message asking if you wish to remove the Add-in.
'   3) Registry corruption.
' you will need to re-register the Add-in by building the $SAFEOBJNAME$Setup project, 
' right click the project in the Solution Explorer, then choose install.
#End Region

<GuidAttribute("D291B3ED-CEA2-46F9-9184-223C64C1CD31"), ProgIdAttribute("Alex11.Connect")> _
Public Class Connect
	
	Implements Extensibility.IDTExtensibility2

	Dim applicationObject as Object
        Dim addInInstance as object
	
	Public Sub OnBeginShutdown(ByRef custom As System.Array) Implements Extensibility.IDTExtensibility2.OnBeginShutdown
	End Sub
	
	Public Sub OnAddInsUpdate(ByRef custom As System.Array) Implements Extensibility.IDTExtensibility2.OnAddInsUpdate
	End Sub
	
	Public Sub OnStartupComplete(ByRef custom As System.Array) Implements Extensibility.IDTExtensibility2.OnStartupComplete
        MsgBox("hi")
    End Sub
	
	Public Sub OnDisconnection(ByVal RemoveMode As Extensibility.ext_DisconnectMode, ByRef custom As System.Array) Implements Extensibility.IDTExtensibility2.OnDisconnection
        ' *** BEGIN CUSTOM CODE. ***
        On Error Resume Next

        ' Disconnect the shared add-in, no matter how the host application 
        ' was shut down. 
        If RemoveMode <> Extensibility.ext_DisconnectMode.ext_dm_HostShutdown Then _
           Call OnBeginShutdown(custom)

        applicationObject = Nothing
        ' *** END CUSTOM CODE. ***

    End Sub
	
	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
        ' *** BEGIN CUSTOM CODE. ***
        ' No matter how the host application started, connect the shared add-in.
        If (connectMode <> Extensibility.ext_ConnectMode.ext_cm_Startup) Then _
           Call OnStartupComplete(custom)
        ' *** END CUSTOM CODE. ***

    End Sub


End Class
The symptom is the same it works for Power Point but not with Word, Excel or Outlook.
Reply With Quote
  #9  
Old 10-04-2007, 04:56 AM
DennisW's Avatar
DennisW DennisW is offline
Junior Contributor
 
Join Date: Mar 2006
Location: Östersund, Sweden
Posts: 268
Default

Quick question: Which version of Office do You use?
__________________
Kind regards,
Dennis

.NET & Excel | 2nd edition PED | MVP
Reply With Quote
  #10  
Old 10-04-2007, 05:59 AM
Alex30 Alex30 is offline
Regular
 
Join Date: Sep 2007
Posts: 51
Default

2003
Reply With Quote
  #11  
Old 10-04-2007, 02:42 PM
DennisW's Avatar
DennisW DennisW is offline
Junior Contributor
 
Join Date: Mar 2006
Location: Östersund, Sweden
Posts: 268
Default

Alex,

I've tested the code in a COM Add-in targeting Word, Excel and PowerPoint. In each software the Add-in works as expected.

In view of my own experience I believe that the KB908002 fix may solve the issue. Install it and let us know the outcome of it.
__________________
Kind regards,
Dennis

.NET & Excel | 2nd edition PED | MVP
Reply With Quote
  #12  
Old 10-04-2007, 02:56 PM
DennisW's Avatar
DennisW DennisW is offline
Junior Contributor
 
Join Date: Mar 2006
Location: Östersund, Sweden
Posts: 268
Default

If the above mentioned hotfix does not solve the Word issue then you may also check out KB907417
__________________
Kind regards,
Dennis

.NET & Excel | 2nd edition PED | MVP
Reply With Quote
  #13  
Old 10-04-2007, 05:01 PM
Alex30 Alex30 is offline
Regular
 
Join Date: Sep 2007
Posts: 51
Default

Wow, unbelievable.
I spent two weeks for this…

Dennis, thanks a lot
Reply With Quote
  #14  
Old 10-05-2007, 01:34 AM
DennisW's Avatar
DennisW DennisW is offline
Junior Contributor
 
Join Date: Mar 2006
Location: Östersund, Sweden
Posts: 268
Default

Alex,

Glad we could help You out with this

Which one of the KB fix resolved the issue?
__________________
Kind regards,
Dennis

.NET & Excel | 2nd edition PED | MVP
Reply With Quote
  #15  
Old 10-05-2007, 02:27 AM
Alex30 Alex30 is offline
Regular
 
Join Date: Sep 2007
Posts: 51
Default

Dennis,
I used the first fix (KB908002).

I have, one more question. The add-in opens another VB .NET application when user clicks the button. This is the command that I use:

Code:
If IO.File.Exists("c:\Documents and Settings\User\My Documents\Visual Studio 2005\Projects\My Application\My Application\bin\Debug\My Application.exe") Then
            System.Diagnostics.Process.Start("c:\Documents and Settings\User\My Documents\Visual Studio 2005\Projects\My Application\My Application\bin\Debug\My Application.exe")

Else
            MsgBox("My Application.exe file was not found")
End If
After clicking the button, the application start form opens, but it has very limited functionality – some forms inside the application can’t be opened.

If I open My Application.exe in a normal way (through Windows Explorer), it works fine.

May be I am using wrong command to open application?
Reply With Quote
  #16  
Old 10-05-2007, 02:48 AM
DennisW's Avatar
DennisW DennisW is offline
Junior Contributor
 
Join Date: Mar 2006
Location: Östersund, Sweden
Posts: 268
Default

Alex,

You need to change the pointer to Excel.exe:

1. Select the command Project | NameofProject Properties from the main meny
2. Click on the Debug tab and select the option "Start external program"
3. Click on the grey button with .... to the right of the field.
4. Save the project

Everytime You execute the add-in from VB it should always start Excel.
__________________
Kind regards,
Dennis

.NET & Excel | 2nd edition PED | MVP
Reply With Quote
  #17  
Old 10-05-2007, 09:43 AM
Alex30 Alex30 is offline
Regular
 
Join Date: Sep 2007
Posts: 51
Default

Dennis,
I think that the problem is not with add-in but with my code.

If I create new VB .NET application with one button that opens another VB .NET application:

Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If IO.File.Exists("c:\Documents and Settings\User\My Documents\Visual Studio 2005\Projects\My Application\My Application\bin\Debug\My Application.exe") Then
            System.Diagnostics.Process.Start("c:\Documents and Settings\User\My Documents\Visual Studio 2005\Projects\My Application\My Application\bin\Debug\My Application.exe")

Else
            MsgBox("My Application.exe file was not found")
End If
    End Sub
The effect is the same: "My Application" start form opens, but it has very limited functionality – some forms inside the application can’t be opened.

If I open My Application.exe in a normal way (through Windows Explorer), it works fine.
Reply With Quote
  #18  
Old 10-05-2007, 03:18 PM
Alex30 Alex30 is offline
Regular
 
Join Date: Sep 2007
Posts: 51
Smile

OK, It is sovlved, I had to set the directory from which the process starts.
Here is the code:

Code:
If IO.File.Exists("c:\Documents and Settings\User\My Documents\Visual Studio 2005\Projects\My Application\My Application\bin\Debug\My Application.exe") Then

            Dim myProcess As New Process

            myProcess.StartInfo.FileName = ("c:\Documents and Settings\User\My Documents\Visual Studio 2005\Projects\My Application\My Application\bin\Debug\My Application.exe")

            myProcess.StartInfo.WorkingDirectory = "c:\Documents and Settings\User\My Documents\Visual Studio 2005\Projects\My Application\My Application\bin\Debug"

            myProcess.Start()
            
        Else
            MsgBox("My Application.exe file was not found")
        End If
Thanks again, Dennis, for solving my problem.
Reply With Quote
  #19  
Old 10-06-2007, 04:45 AM
DennisW's Avatar
DennisW DennisW is offline
Junior Contributor
 
Join Date: Mar 2006
Location: Östersund, Sweden
Posts: 268
Default

Alex,

Sorry for not reading your follow up question more carefully.

Anyway, I guess we now can say "case close"
__________________
Kind regards,
Dennis

.NET & Excel | 2nd edition PED | MVP
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Creating COM add-inn for office application
Creating COM add-inn for office application
Creating COM add-inn for office application Creating COM add-inn for office application
Creating COM add-inn for office application
Creating COM add-inn for office application
Creating COM add-inn for office application Creating COM add-inn for office application Creating COM add-inn for office application Creating COM add-inn for office application Creating COM add-inn for office application Creating COM add-inn for office application Creating COM add-inn for office application
Creating COM add-inn for office application
Creating COM add-inn for office application
 
Creating COM add-inn for office application
Creating COM add-inn for office application
 
-->