Visual Studio Development Bookmark and Share   
 index > Visual Studio Tools for Office > How can i hide the word 2007 menu bar and command bar?
 

How can i hide the word 2007 menu bar and command bar?

I can hide the word 2003 menu bar and command bar
but the code did not work in word 2007,
can anyone help me?thanks



starinight  Friday, August 28, 2009 8:18 AM
Office 2007 does not have *menu bar" or "command bar" any more, the way Office 2003 did. It has the Ribbon, and while the Ribbon can be minimized (to show only the Ribbon tabs across the top) it cannot be completely hidden. The only tool provided for you is the ToggleRibbon method of the Window object. This does not, unfortunately, tell you whether the Ribbon is already minimized or not. You'd need to do some calculations. The following bit of VBA code gives you an idea how you could procede but does not cover all possible situations (such as the height of the top margin, whether margins are being suppressed, etc.)

Sub TurnRibbonOff()
Dim win As Word.Window
Dim pLeft As Long, pTop As Long, pHeight As Long, pWidth As Long
Dim rngSel As Word.Range, rngDocTop As Word.Range, oRng As Object

Set win = ActiveWindow
Set rngSel = Selection.Range
Set rngDocTop = ActiveDocument.Content
rngDocTop.Collapse wdCollapseStart 'Top of the document
rngDocTop.Select
Set oRng = rngDocTop
win.LargeScroll Up:=10 'Force the maximum scroll
win.GetPoint pLeft, pTop, pHeight, pWidth, oRng
Debug.Print win.Height, Application.UsableHeight, pLeft, pTop, pHeight, pWidth
rngSel.Select
If pTop > 300 Then
win.ToggleRibbon
End If
End Sub

Cindy Meister, VSTO/Word MVP
  • Marked As Answer bystarinight Tuesday, September 01, 2009 5:50 AM
  •  
Cindy Meister  Friday, August 28, 2009 9:26 AM
Office 2007 does not have *menu bar" or "command bar" any more, the way Office 2003 did. It has the Ribbon, and while the Ribbon can be minimized (to show only the Ribbon tabs across the top) it cannot be completely hidden. The only tool provided for you is the ToggleRibbon method of the Window object. This does not, unfortunately, tell you whether the Ribbon is already minimized or not. You'd need to do some calculations. The following bit of VBA code gives you an idea how you could procede but does not cover all possible situations (such as the height of the top margin, whether margins are being suppressed, etc.)

Sub TurnRibbonOff()
Dim win As Word.Window
Dim pLeft As Long, pTop As Long, pHeight As Long, pWidth As Long
Dim rngSel As Word.Range, rngDocTop As Word.Range, oRng As Object

Set win = ActiveWindow
Set rngSel = Selection.Range
Set rngDocTop = ActiveDocument.Content
rngDocTop.Collapse wdCollapseStart 'Top of the document
rngDocTop.Select
Set oRng = rngDocTop
win.LargeScroll Up:=10 'Force the maximum scroll
win.GetPoint pLeft, pTop, pHeight, pWidth, oRng
Debug.Print win.Height, Application.UsableHeight, pLeft, pTop, pHeight, pWidth
rngSel.Select
If pTop > 300 Then
win.ToggleRibbon
End If
End Sub

Cindy Meister, VSTO/Word MVP
  • Marked As Answer bystarinight Tuesday, September 01, 2009 5:50 AM
  •  
Cindy Meister  Friday, August 28, 2009 9:26 AM

The Ribbon can be completely hidden but it is a little more difficult.  If you look at the DSOFramer source code you can see they are sending an OLE command (OLECMDID_HIDETOOLBARS = 24) to achieve this. To see examples of how this looks, open a word document from within Internet Explorer - see either http://support.microsoft.com/default.aspx/kb/304662 or http://support.microsoft.com/kb/927009/.

  • Proposed As Answer byLdcroberts Friday, October 16, 2009 1:47 AM
  •  
Ldcroberts  Thursday, October 15, 2009 10:38 PM

You can use google to search for other answers

Custom Search

More Threads

• Draggable ListBox - Excel
• Incorporate CustomXMLPart in Excel and link nodes to cells
• VSTO project word 2003 addIn - various problems faced
• Select a Range by a Cell
• Sheet rename event?
• Excel 2003 (VSTO SE) Add-In: CommandBar Change Event Issue When a Control Gets Added in an Extended CommandBar
• Combining InfoPath Documents
• How to add scalene Triangle to MS WORD
• Microsoft PSS VSTO 2005 Client Troubleshooter Download
• Excel addin error on load