Sei sulla pagina 1di 4

Firstly, I assume you meant to refer to the Worksheet Menu Bar rather than the Standard toolbar as the

one you want to keep visible, since it is the one that has the File and Help menus. Here is some code that you can add to your ThisWorkbook module that should do what you want: Option Base 1 Dim MoveAfterReturn As Boolean Dim MoveAfterReturnDirection As XlDirection Dim CBvisible() As Boolean Private Sub Workbook_Open() Dim i As Integer

'Hide all commandbars, including formula bar, but not Worksheet Menu Bar With Application ReDim CBvisible(.CommandBars.Count) For i = 1 To .CommandBars.Count CBvisible(i) = .CommandBars(i).Visible 'save original visibility state If .CommandBars(i).Name <> "Worksheet Menu Bar" Then If .CommandBars(i).Visible Then .CommandBars(i).Visible = False End If Next i .DisplayFormulaBar = False With .CommandBars("Worksheet Menu Bar") For i = 1 To .Controls.Count Select Case .Controls(i).Caption Case "&File", "&Help" Case Else .Controls(i).Visible = False End Select Next i End With 'save current settings so they can be restored later, 'then set enter key to move down MoveAfterReturn = Application.MoveAfterReturn

MoveAfterReturnDirection = Application.MoveAfterReturnDirection .MoveAfterReturn = True .MoveAfterReturnDirection = xlToRight End With 'Turn off row and column headings ActiveWindow.DisplayHeadings = False

End Sub Private Sub Workbook_BeforeClose(Cancel As Boolean) Dim i As Integer

'Unhide all commandbars, including formula bar, but not Worksheet Menu Bar With Application For i = 1 To .CommandBars.Count If .CommandBars(i).Visible <> CBvisible(i) Then .CommandBars(i).Visible = CBvisible(i) End If Next i .DisplayFormulaBar = True With .CommandBars("Worksheet Menu Bar") For i = 1 To .Controls.Count .Controls(i).Visible = True Next i End With 'restore move-after-enter original settings .MoveAfterReturn = MoveAfterReturn .MoveAfterReturnDirection = MoveAfterReturnDirection End With 'Turn on row and column headings ActiveWindow.DisplayHeadings = True End Sub To place this code in the ThisWorkbook module, simply right-click on the Excel icon at the left end of the Worksheet Menu Bar, select View Code, and paste this code into the Code pane.

You will notice that I created some variables and an array to store your original settings (e.g., which toolbars are visible). This is why I'm giving you an additional routine: Sub cbars() CommandBars(24).Visible = True CommandBars(14).Visible = True CommandBars(1).Visible = True CommandBars(3).Visible = True CommandBars(4).Visible = True End Sub Since an error in Excel (perhaps in some other macro) causes all variable contents to be cleared, and thus these temporary storage variables could be cleared, this routine will at least quickly get you back the most often used toolbars. You should place it in a standard macro module. Keep Excelling. Damon ================

Menutup Semua Workbook Yang Tidak Aktif

Pekerjaan kantor yang menumpuk cukup menyita banyak perhatian karena banyaknya dokumendokumen excel yang harus dibuka karena antara dokumen satu dengan yang lainnya saling berkaitan, akibatnya tampilan dokumen yang terbuka (thumbnail) menumpuk di taskbar.

Bagaimana untuk menutup semua dokumen yang sudah terbuka ketika membuka dokumen lain ?
Ketika sebuah dokumen dibuka maka secara otomatis membuat dokumen lain yang terbuka menjadi pasif atau tidak aktif. Kode Macro berikut ini berfungsi untuk menutup semua dokumen excel - sementara dokumen yang aktif akan tetap terbuka Public Sub TutupSemuaDokumen() Dim Wb As Workbook Dim AWb As String AWb = ActiveWorkbook.Name 'Menutup semua dokumen pasif dan menyimpannya

For Each Wb In Workbooks If Wb.Name <> AWb Then Wb.Close savechanges:=True End If Next Wb End Sub Kode di atas letakkan dalam sebuah module, caranya : 1. Buka jendela Microsoft Visual Basic 2. Klik menu Insert dan pilih Module 3. Paste kode di atas di jendela kode yang tersedia Menjalankan module Jika menginginkan kode di atas berjalan secara otomatis ketika sebuah dokumen dibuka, maka letakkan kode berikut di ThisWorkbook Private Sub Workbook_Open() Call TutupSemuaDokumen End Sub
===============

Potrebbero piacerti anche