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