Hiding tabs and menus, toolbars, etc.

M

Moiz

I want to open an excel file so that when it opens it hides all menus, tabs,
toolbars, etc.

then when it closes it resets everything to its origininal settings

can you advise the code, please.

Moiz
 
G

Guest

I found this code somewhere on the forum or searching online. It hides all
toolbars, scrollbars, and some other things when the workbook is activated,
then shows them again when deactivated (especially for switching between
workbooks)

Place all of the following in "thisWorkbook" object code. Create a sheet in
your workbook to hold the names of the toolbars that get hidden (able to
accomodate multiple users this way). Make sure to change the code below by
inserting the name of your workbook and the sheet that will contain the
toolbar names.


Private Sub Workbook_Activate()
Dim LoginAccess As Variant
Dim TBarCount As Integer
Dim cbar As CommandBar
On Error Resume Next
'Removes Toolbars
Sheets("sheet name").Range("A:A").ClearContents
TBarCount = 0
For Each cbar In Application.CommandBars
If cbar.Type = msoBarTypeNormal Then
If cbar.Visible Then
TBarCount = TBarCount + 1
Workbooks("wb name").Sheets("sheet
name").Cells(TBarCount, 1) = _
cbar.Name
cbar.Visible = False
End If
End If
Next cbar
With Application
.DisplayFormulaBar = False
.DisplayStatusBar = False
.DisplayScrollBars = False
End With
End Sub



Private Sub Workbook_Deactivate()
Dim Row As Long
Dim TBar As String

Row = 1
TBar = Workbooks("wb name").Sheets("sheet name").Cells(Row, 1)
Do While TBar <> ""
Application.CommandBars(TBar).Visible = True
Row = Row + 1
TBar = Workbooks("wb name").Sheets("sheet name").Cells(Row, 1)
Loop
With Application
.DisplayFormulaBar = True
.DisplayStatusBar = True
.DisplayScrollBars = True
End With
End Sub
 

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