Office addin not getting deleted , vb .net

S

sajin

Hi,
I developed an application which creates some addin in office (
word,excel and powerpoint) , i created a console application which wil
be called during uninstallation of the addin , but the addin toolbar
never goes , where am i doing wrong

'code is as follows ( VS 2005 , VB.Net)

Imports System.IO
Module DeleteToolBar
Private WordAppClass As New Word.ApplicationClass
Private ExcelAppClass As New Excel.ApplicationClass
Private PPTAppClass As New PowerPoint.ApplicationClass


Sub Main()
Try
'The MyAddinBar toolbar has to be removed from Word while
uninstalling the My.0
Dim oMissing As Object
Dim cmdBar As Office.CommandBar
Dim cmdCntrl As Office.CommandBarControl
Dim oSaveChanges As Object
Dim oOriginalFormat As Object
oMissing = System.Reflection.Missing.Value
oSaveChanges = True
oOriginalFormat = Nothing
For Each cmdBar In WordAppClass.CommandBars
' If the commandbar name is "MyAddinBar" , then delete
the commandbar from the word applicaton
If cmdBar.Name = "MyAddinBar Toolbar" Then
cmdBar.Delete()
End If

If cmdBar.Name = "MyAddinBar" Then
'For Each cmdCntrl In cmdBar.Controls
' cmdCntrl.Delete()
'Next
cmdBar.Delete()

End If
If cmdBar.Name = "My Calculate" Then

cmdBar.Delete()
End If
If cmdBar.Name = "Copy Cells" Then

cmdBar.Delete()
End If
Next
WordAppClass.Quit(oMissing, oMissing, oMissing)
System.Threading.Thread.Sleep(5000)
For Each cmdBar In ExcelAppClass.CommandBars
' then delete the commandbar from the applicaton
If cmdBar.Name = "MyAddinBar Toolbar" Then
cmdBar.Delete()
End If
If cmdBar.Name = "MyAddinBar" Then

cmdBar.Delete()
End If
If cmdBar.Name = "My Calculate" Then

cmdBar.Delete()
End If
If cmdBar.Name = "Copy Cells" Then

cmdBar.Delete()
End If
Next
' After the modification, the application has to save the
changes
ExcelAppClass.Quit()
For Each cmdBar In PPTAppClass.CommandBars
' then delete the commandbar from the applicaton
If cmdBar.Name.Equals("MyAddinBar Toolbar") Then
cmdBar.Delete()
End If
If cmdBar.Name = "MyAddinBar" Then

cmdBar.Delete()
End If
If cmdBar.Name = "My Calculate" Then

cmdBar.Delete()
End If
If cmdBar.Name = "Copy Cells" Then

cmdBar.Delete()
End If
Next
' After the modification, the application has to save the
changes
PPTAppClass.Quit()
Catch ex As Exception
End Try



End Sub


End Module



Please help me.
Thanks in advance
Sajin
 
X

XL-Dennis

Sajin,

I suggest that You use the Tag property of the commandbar as well as the
controls.
The following article shows demonstrate how You can use it:
http://www.excelkb.com/article.aspx?id=10198&cNode=4K2U2U

The best solution to delete a whole commandbar is to use its Tag property as
the following snippet code shows:

g_xlGlobal.xlApp.CommandBars.FindControl(Tag:=g_stTag).Delete

It can also be applied to individual controls.

I assume You create the commandbar in the OnConnection event in the
Connection class and it's important that You in the Disconnection event set
the variables to nothing and also call the Garbage Collector in the following
way:

Variable = Nothing
GC.Collect()
GC.WaitForPendingFinalizers()

---------------
With kind regards,
Dennis
Weekly Blog .NET & Excel: http://xldennis.wordpress.com/
My English site: http://www.excelkb.com/default.aspx
My Swedish site: http://www.xldennis.com/
 
P

pavan

Dennis,
I guess only for Word we cannot remove the toolbar (buttons) once
added. The reason for this is that upon adding of toolbar Normal.dot
gets modified and for some strange reason we cannot revert it back. I
also found that temporary attribute for the toolbar is "not respected
by word". To overcome this we need to add a custom template, add
toolbar to it and delete it during uninstalltion. This way we do not
touch normal.dot

Sajin,
Refer to this thread to
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=356963&SiteID=1&mode=1&PageID=0
to find more details. I had faced the same issue when I first started
word add-in development. Fortunately I got timely help.

Hope this helps
Regards,
Pavan
 
P

pavan

Oh...pardon me! I guess I had put fwd this point to you earlier Dennis!
Sorry to persist this! :)
 

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