Hi Alex,
Have you tried the steps I posted in my last post?
1. simplified the code similar as below
Dim wdApp As Word.Application
Public Sub OnBeginShutdown(ByRef custom As System.Array) Implements
Extensibility.IDTExtensibility2.OnBeginShutdown
Dim cmBar As Office.CommandBar
Dim cbb As Office.CommandBarButton
Debug.WriteLine("OnBeginShutdown")
Try
cmBar = wdApp.CommandBars("Test")
cbb = cmBar.FindControl(, , "TestTag", , )
Catch ex As Exception
Debug.WriteLine(ex.ToString())
End Try
If Not cbb Is Nothing Then
cbb.Delete()
End If
If Not cmBar Is Nothing Then
cmBar.Delete()
End If
Marshal.ReleaseComObject(cbb)
Marshal.ReleaseComObject(cmBar)
cbb = Nothing
cmBar = Nothing
End Sub
Public Sub OnAddInsUpdate(ByRef custom As System.Array) Implements
Extensibility.IDTExtensibility2.OnAddInsUpdate
Debug.WriteLine("OnAddInsUpdate")
End Sub
Dim WithEvents cbb As Office.CommandBarButton
Public Sub OnStartupComplete(ByRef custom As System.Array) Implements
Extensibility.IDTExtensibility2.OnStartupComplete
Debug.WriteLine("OnStartupComplete")
Dim cmBar As Office.CommandBar
If MsgBox("Do you want Create Toolbar?", MsgBoxStyle.YesNo) =
MsgBoxResult.Yes Then
cmBar = wdApp.CommandBars.Add("Test", , , True)
cmBar.Visible = True
cmBar.Position = MsoBarPosition.msoBarTop
cbb =
cmBar.Controls.Add(Office.MsoControlType.msoControlButton, , , , True)
cbb.Caption = "TestBar"
cbb.FaceId = 17
cbb.Tag = "TestTag"
Debug.WriteLine("Create Toolbar Complete")
End If
Marshal.ReleaseComObject(cmBar)
cmBar = Nothing
End Sub
Public Sub OnDisconnection(ByVal RemoveMode As
Extensibility.ext_DisconnectMode, ByRef custom As System.Array) Implements
Extensibility.IDTExtensibility2.OnDisconnection
Debug.WriteLine("OnDisconnection")
If Not RemoveMode = ext_DisconnectMode.ext_dm_HostShutdown Then
OnBeginShutdown(custom)
End If
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
wdApp = DirectCast(application, Word.Application)
Debug.WriteLine("OnConnection")
If Not connectMode = ext_ConnectMode.ext_cm_Startup Then
OnStartupComplete(custom)
End If
End Sub
Private Sub cbb_Click(ByVal Ctrl As
Microsoft.Office.Core.CommandBarButton, ByRef CancelDefault As Boolean)
Handles cbb.Click
Dim fm As New Form1
fm.ShowDialog()
' MsgBox("Test") ' I have tried msgbox/showdialog but I still can
not reproduce the problem
End Sub
2. Open the word and a notepad application
3. Now make the word as the foregroud application, and click the button, a
modal form will show
4. close "X" to close the modal form
5. and now the word is the foregroud application, the notepad will not be
the foregroud window
If I have any misunderstanding, please feel free to post here.
If you still have any concern, please post your simplified test code
together with the detailed reproduce steps for us to further research.
Best regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! -
www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.