M
Michael R
I have disabled a Word built-in menu item using C# code. When the app
closes the normal.dot template has increased in size by 512 bytes. However,
the same code in VB.Net does not cause this problem. The code is below.
Any ideas as to what VB.Net hides from me that I can use in the C# code to
prevent this problem? Thanks.
VB.Net code
Private Sub HideMenu(ByVal HideMenu As Boolean)
'oWordApp is the Word.Application object
Dim oCmdBars As Office.CommandBars
Dim oPopUp As Office.CommandBarPopup
oCmdBars = oWordApp.CommandBars
oPopUp = oCmdBars("Menu Bar").Controls("F&ormat")
oPopUp.Visible = Not HideMenu
oPopUp.Enabled = Not HideMenu
End Sub
C# Code
private static void HideMenu(bool HideMenu)
{
CommandBars oCmdBars = null;
CommandBarPopup oPopUp = null;
try
{
'oWordApp is the Word.Application object
oCmdBars = oWordApp.CommandBars;
oPopUp = (CommandBarPopup)oCmdBars["Menu Bar"].Controls["F&ormat"];
//True to hide, false to show menus
oPopUp.Visible = !HideMenu;
oPopUp.Enabled = !HideMenu;
}
catch { }
finally
{
if ( oPopUp != null ) Marshal.ReleaseComObject(oPopUp);
if ( oCmdBars != null ) Marshal.ReleaseComObject(oCmdBars);
}
}
P.S. If I comment out the oPopUp.Visible = !HideMenu; and oPopUp.Enabled =
!HideMenu; in the C# code I do not have the problem!
closes the normal.dot template has increased in size by 512 bytes. However,
the same code in VB.Net does not cause this problem. The code is below.
Any ideas as to what VB.Net hides from me that I can use in the C# code to
prevent this problem? Thanks.
VB.Net code
Private Sub HideMenu(ByVal HideMenu As Boolean)
'oWordApp is the Word.Application object
Dim oCmdBars As Office.CommandBars
Dim oPopUp As Office.CommandBarPopup
oCmdBars = oWordApp.CommandBars
oPopUp = oCmdBars("Menu Bar").Controls("F&ormat")
oPopUp.Visible = Not HideMenu
oPopUp.Enabled = Not HideMenu
End Sub
C# Code
private static void HideMenu(bool HideMenu)
{
CommandBars oCmdBars = null;
CommandBarPopup oPopUp = null;
try
{
'oWordApp is the Word.Application object
oCmdBars = oWordApp.CommandBars;
oPopUp = (CommandBarPopup)oCmdBars["Menu Bar"].Controls["F&ormat"];
//True to hide, false to show menus
oPopUp.Visible = !HideMenu;
oPopUp.Enabled = !HideMenu;
}
catch { }
finally
{
if ( oPopUp != null ) Marshal.ReleaseComObject(oPopUp);
if ( oCmdBars != null ) Marshal.ReleaseComObject(oCmdBars);
}
}
P.S. If I comment out the oPopUp.Visible = !HideMenu; and oPopUp.Enabled =
!HideMenu; in the C# code I do not have the problem!