Suppression menus et barres dans excel

Résolu
supermoun Messages postés 39 Statut Membre -  
 kilian -
Bonjour à tous,
J'ai récupéré une macro qui me supprime toutes les barres et menus mais est-il possible de garder le menu FICHIER
afin de pouvoir par exemple enregistrer ou imprimer.
Ci-dessous les macros à l'ouverture et femeture du classeur.

Private Sub Workbook_Activate()
Dim Barre As CommandBar
Set Barres = New Collection
For Each Barre In Application.CommandBars
If Barre.Visible = True And _
Barre.Name <> "Worksheet Menu Bar" Then
Barres.Add Barre.Name
Barre.Visible = False
End If
Next Barre
Application.CommandBars("worksheet menu bar").Enabled = False
End Sub

Private Sub Workbook_Deactivate()
Dim Barre As Variant
For Each Barre In Barres
Application.CommandBars(Barre).Visible = True
Next Barre
Application.CommandBars("worksheet menu bar").Enabled = True
End Sub

Dans l'attente d'une réponse, merci.
Configuration: Windows XP
Internet Explorer 6.0

4 réponses

  1. ouh
     
    Bonjour voici une méga macro très artisanale mais qui marche pour le problème du topic

    En gros, à l'ouverture du fichier la macro teste si telle ou telle barre d'outil est présente, si oui, elle l'enlève et elle met la valeur 1 dans une case de la feuille "barres" qu'il faut que vous créiez (créiez??, ça sonne drôle).
    A la fermeture, la macro teste si il y a 1 ou 0, et elle remet la barre le cas échéant.

    Private Sub Workbook_Open()

    Application.ScreenUpdating = False

    With ActiveWindow
    .DisplayHeadings = False
    .DisplayHorizontalScrollBar = False
    .DisplayVerticalScrollBar = False
    Application.DisplayFormulaBar = False
    Application.DisplayStatusBar = False
    End With

    Sheets("barres").Activate
    ActiveSheet.Unprotect

    'on remet toutes les valeurs à 0
    Range("B41:L43").Select
    Selection.FormulaR1C1 = "0"

    If Application.CommandBars("Standard").Visible = True Then
    Application.CommandBars("Standard").Visible = False
    Range("B41").Select
    ActiveCell.FormulaR1C1 = "1"
    End If

    If Application.CommandBars("Formatting").Visible = True Then
    Application.CommandBars("Formatting").Visible = False
    Range("C41").Select
    ActiveCell.FormulaR1C1 = "1"
    End If

    If Application.CommandBars("Borders").Visible = True Then
    Application.CommandBars("Borders").Visible = False
    Range("D41").Select
    ActiveCell.FormulaR1C1 = "1"
    End If

    If Application.CommandBars("Chart").Visible = True Then
    Application.CommandBars("Chart").Visible = False
    Range("E41").Select
    ActiveCell.FormulaR1C1 = "1"
    End If

    If Application.CommandBars("Control Toolbox").Visible = True Then
    Application.CommandBars("Control Toolbox").Visible = False
    Range("F41").Select
    ActiveCell.FormulaR1C1 = "1"
    End If

    If Application.CommandBars("Drawing").Visible = True Then
    Application.CommandBars("Drawing").Visible = False
    Range("G41").Select
    ActiveCell.FormulaR1C1 = "1"
    End If

    If Application.CommandBars("External Data").Visible = True Then
    Application.CommandBars("External Data").Visible = False
    Range("H41").Select
    ActiveCell.FormulaR1C1 = "1"
    End If

    If Application.CommandBars("Forms").Visible = True Then
    Application.CommandBars("Forms").Visible = False
    Range("I41").Select
    ActiveCell.FormulaR1C1 = "1"
    End If

    If Application.CommandBars("Formula Auditing").Visible = True Then
    Application.CommandBars("Formula Auditing").Visible = False
    Range("J41").Select
    ActiveCell.FormulaR1C1 = "1"
    End If

    If Application.CommandBars("List").Visible = True Then
    Application.CommandBars("List").Visible = False
    Range("K41").Select
    ActiveCell.FormulaR1C1 = "1"
    End If

    If Application.CommandBars("Picture").Visible = True Then
    Application.CommandBars("Picture").Visible = False
    Range("L41").Select
    ActiveCell.FormulaR1C1 = "1"
    End If

    If Application.CommandBars("PivotTable").Visible = True Then
    Application.CommandBars("PivotTable").Visible = False
    Range("B42").Select
    ActiveCell.FormulaR1C1 = "1"
    End If

    If Application.CommandBars("Protection").Visible = True Then
    Application.CommandBars("Protection").Visible = False
    Range("C42").Select
    ActiveCell.FormulaR1C1 = "1"
    End If

    If Application.CommandBars("Reviewing").Visible = True Then
    Application.CommandBars("Reviewing").Visible = False
    Range("D42").Select
    ActiveCell.FormulaR1C1 = "1"
    End If

    If Application.CommandBars("Task Pane").Visible = True Then
    Application.CommandBars("Task Pane").Visible = False
    Range("E42").Select
    ActiveCell.FormulaR1C1 = "1"
    End If

    If Application.CommandBars("Text To Speech").Visible = True Then
    Application.CommandBars("Text To Speech").Visible = False
    Range("F42").Select
    ActiveCell.FormulaR1C1 = "1"
    End If

    If Application.CommandBars("Visual Basic").Visible = True Then
    Application.CommandBars("Visual Basic").Visible = False
    Range("G42").Select
    ActiveCell.FormulaR1C1 = "1"
    End If

    If Application.CommandBars("Watch Window").Visible = True Then
    Application.CommandBars("Watch Window").Visible = False
    Range("H42").Select
    ActiveCell.FormulaR1C1 = "1"
    End If

    If Application.CommandBars("Web").Visible = True Then
    Application.CommandBars("Web").Visible = False
    Range("I42").Select
    ActiveCell.FormulaR1C1 = "1"
    End If

    If Application.CommandBars("WordArt").Visible = True Then
    Application.CommandBars("WordArt").Visible = False
    Range("J42").Select
    ActiveCell.FormulaR1C1 = "1"
    End If

    If Application.CommandBars("Exit Design Mode").Visible = True Then
    Application.CommandBars("Exit Design Mode").Visible = False
    Range("C43").Select
    ActiveCell.FormulaR1C1 = "1"
    End If

    If Application.CommandBars("Full Screen").Visible = True Then
    Application.CommandBars("Full Screen").Visible = False
    Range("D43").Select
    ActiveCell.FormulaR1C1 = "1"
    End If

    If Application.CommandBars("Organization Chart").Visible = True Then
    Application.CommandBars("Organization Chart").Visible = False
    Range("E43").Select
    ActiveCell.FormulaR1C1 = "1"
    End If

    If Application.CommandBars("Shadow Settings").Visible = True Then
    Application.CommandBars("Shadow Settings").Visible = False
    Range("F43").Select
    ActiveCell.FormulaR1C1 = "1"
    End If

    If Application.CommandBars("Drawing Canvas").Visible = True Then
    Application.CommandBars("Drawing Canvas").Visible = False
    Range("G43").Select
    ActiveCell.FormulaR1C1 = "1"
    End If

    If Application.CommandBars("Diagram").Visible = True Then
    Application.CommandBars("Diagram").Visible = False
    Range("H43").Select
    ActiveCell.FormulaR1C1 = "1"
    End If

    If Application.CommandBars("Compare Side by Side").Visible = True Then
    Application.CommandBars("Compare Side by Side").Visible = False
    Range("I43").Select
    ActiveCell.FormulaR1C1 = "1"
    End If

    If Application.CommandBars("Circular Reference").Visible = True Then
    Application.CommandBars("Circular Reference").Visible = False
    Range("J43").Select
    ActiveCell.FormulaR1C1 = "1"
    End If

    If Application.CommandBars("Chart Menu Bar").Visible = True Then
    Application.CommandBars("Chart Menu Bar").Visible = False
    Range("K43").Select
    ActiveCell.FormulaR1C1 = "1"
    End If

    If Application.CommandBars("3-D Settings").Visible = True Then
    Application.CommandBars("3-D Settings").Visible = False
    Range("L43").Select
    ActiveCell.FormulaR1C1 = "1"
    End If

    With ActiveWindow
    .DisplayHeadings = False
    .DisplayHorizontalScrollBar = False
    .DisplayVerticalScrollBar = False
    Application.DisplayFormulaBar = False
    Application.DisplayStatusBar = False
    End With

    Application.ScreenUpdating = True

    End If

    ActiveSheet.Protect

    End Sub

    Et voici la mega macro pour que ça remette les barres telles qu'elles était avant l'ouverture du fichier, c'est toujours le même test, si telle case contient la valeur 1 et bien on remet la barre correspondante

    Private Sub Workbook_BeforeClose(Cancel As Boolean)

    Application.ScreenUpdating = False

    'remet l'affichage des colonnes et lignes et barres de défilement

    Sheets("barres").Activate
    ActiveSheet.Unprotect
    With ActiveWindow
    .DisplayHeadings = True
    .DisplayHorizontalScrollBar = True
    .DisplayVerticalScrollBar = True
    Application.DisplayFormulaBar = True
    Application.DisplayStatusBar = True

    End With

    If Range("B41").Value = "1" Then
    Application.CommandBars("Standard").Visible = True
    End If

    If Range("C41").Value = "1" Then
    Application.CommandBars("Formatting").Visible = True
    End If

    If Range("D41").Value = "1" Then
    Application.CommandBars("Borders").Visible = True
    End If

    If Range("E41").Value = "1" Then
    Application.CommandBars("Chart").Visible = True
    End If

    If Range("F41").Value = "1" Then
    Application.CommandBars("Control Toolbox").Visible = True
    End If

    If Range("G41").Value = "1" Then
    Application.CommandBars("Drawing").Visible = False
    End If

    If Range("H41").Value = "1" Then
    Application.CommandBars("External Data").Visible = True
    End If

    If Range("I41").Value = "1" Then
    Application.CommandBars("Forms").Visible = True
    End If

    If Range("J41").Value = "1" Then
    Application.CommandBars("Formula Auditing").Visible = True
    End If

    If Range("K41").Value = "1" Then
    Application.CommandBars("List").Visible = True
    End If

    If Range("L41").Value = "1" Then
    Application.CommandBars("Picture").Visible = True
    End If

    If Range("B42").Value = "1" Then
    Application.CommandBars("PivotTable").Visible = True
    End If

    If Range("C42").Value = "1" Then
    Application.CommandBars("Protection").Visible = True
    End If

    If Range("D42").Value = "1" Then
    Application.CommandBars("Reviewing").Visible = True
    End If

    If Range("E42").Value = "1" Then
    Application.CommandBars("Task Pane").Visible = True
    End If

    If Range("F42").Value = "1" Then
    Application.CommandBars("Text To Speech").Visible = True
    End If

    If Range("G42").Value = "1" Then
    Application.CommandBars("Visual Basic").Visible = True
    End If

    If Range("H42").Value = "1" Then
    Application.CommandBars("Watch Window").Visible = True
    End If

    If Range("I42").Value = "1" Then
    Application.CommandBars("Web").Visible = True
    End If

    If Range("J42").Value = "1" Then
    Application.CommandBars("WordArt").Visible = True
    End If

    If Range("C43").Value = "1" Then
    Application.CommandBars("Exit Design Mode").Visible = True
    End If
    If Range("D43").Value = "1" Then
    Application.CommandBars("Full Screen").Visible = True
    End If
    If Range("E43").Value = "1" Then
    Application.CommandBars("Organization Chart").Visible = True
    End If
    If Range("F43").Value = "1" Then
    Application.CommandBars("Shadow Settings").Visible = True
    End If
    If Range("G43").Value = "1" Then
    Application.CommandBars("Drawing Canvas").Visible = True
    End If
    If Range("H43").Value = "1" Then
    Application.CommandBars("Diagram").Visible = True
    End If
    If Range("I43").Value = "1" Then
    Application.CommandBars("Compare Side by Side").Visible = True
    End If
    If Range("J43").Value = "1" Then
    Application.CommandBars("Circular Reference").Visible = True
    End If
    If Range("K43").Value = "1" Then
    Application.CommandBars("Chart Menu Bart").Visible = True
    End If
    If Range("L43").Value = "1" Then
    Application.CommandBars("3-D Settings").Visible = True
    End If

    ActiveSheet.Protect

    Application.ScreenUpdating = True

    End Sub
    3
    1. Raymond PENTIER Messages postés 58216 Date d'inscription   Statut Contributeur Dernière intervention   17 482
       
      Tu ne crains pas que ta proposition arrive un peu tard ? Cette discussion est classée comme résolue depuis le 10 septembre de l'an dernier . Un vraie gestation de 9 mois ...
      0
    2. kilian
       
      Un grand merci car c'est excatement ça que beaucoup de monde recherche ! génial !
      0
  2. Claude Claude Messages postés 1757 Statut Membre 584
     
    La barre de menus que tu veux conserver est en français "Barre de menus - feuille de calcul".

    Il faut que tu adaptes ta macro pour tester et exclure de cette barre du non-affichage.
    2
  3. Raymond PENTIER Messages postés 58216 Date d'inscription   Statut Contributeur Dernière intervention   17 482
     
    Bonjour, supermoun

    Tant qu'à avoir au moins un menu, autant disposer de toute la barre de menus en laissant tomber ta macro et en faisant Affichage/Plein écran !
    1
    1. supermoun Messages postés 39 Statut Membre 7
       
      Bonjour Raymond,

      D'accord pour la forme mais mon projet,c'est de garder que le menu fichier
      afin de verrouiller les autres possibilités de modifications de la feuille.
      Merci pour la réponse.
      A+
      0
  4. Raymond PENTIER Messages postés 58216 Date d'inscription   Statut Contributeur Dernière intervention   17 482
     
    Salut, supermoun.

    Si ton but est seulement de verrouiller l'accès à tes formules, formats ou mises en page, utilise plutôt les outils de protection : Tu utilises Format/Cellule/Protection pour déverrouiller les cellules dont tu autoriseras la modification (saisie de variables) puis tu fais Outils/Protection/Protéger la feuille et tu choisis les actions à autoriser.

    NB : Chez nous, en Guadeloupe on ti moun' veut dire un enfant, une petite personne
    1