Sélectionner plusieurs feuilles à masquer dans une ListBox

Résolu
hokousai Messages postés 7 Statut Membre -  
hokousai Messages postés 7 Statut Membre -
Bonsoir,
J'ai un UserForm dans lequel il y a une ListBox pour sectionner les feuilles à imprimer.
Je souhaiterai que certaine feuille ne soit pas visible dans la ListBox.
En sachant, que dans l'original du projet il y aura 5 à 6 Feuilles à masquer.
Ce code ci-dessous masque la feuille index.
Private Sub UserForm_Initialize()
Dim S As Worksheet
ListBox1.MultiSelect = fmMultiSelectExtended
For Each S In Worksheets
If Not S.Name = "Index" Then
ListBox1.AddItem S.Name
End If
Next
TextBox1 = 0
End Sub

Je ne trouve pas de code pour masquer plusieurs feuilles à la suite.
J’aurais besoin de votre aide.
Je vous remercie par avance.

3 réponses

  1. cs_Le Pivert Messages postés 8437 Statut Contributeur 730
     
    Bonjour,

    tu n'as pas besoin de les masquer!

    Il suffit de sélectionner dans la ListBox les feuilles à imprimer comme ceci:

    Option Explicit
    Private Sub CommandButton1_Click()
     Dim i As Byte
     Dim nom As String
         'boucle sur les éléments de la listbox
        For i = 0 To ListBox1.ListCount - 1
            If ListBox1.Selected(i) = True Then
          nom = ListBox1.List(i)
          MsgBox nom
          'mettre le code des feuilles à imprimer ici en se servant de la variable nom
        End If
        Next i
    End Sub
    Private Sub UserForm_Initialize()
    Dim S As Worksheet
    ListBox1.MultiSelect = fmMultiSelectExtended
    For Each S In Worksheets
    ListBox1.AddItem S.Name
    Next
    End Sub
    


    1
  2. hokousai Messages postés 7 Statut Membre
     
    Merci Le Pivert,



    Si j'ai bien compris, je dois lister les feuilles à imprimer plutôt que de masquer les feuilles que je ne veux pas lister ?
    Voici ci-desous les code complet du UserForm :

    Private Sub apercu_Click()

    Dim i As Integer

    UserForm1.Hide

    With ListBox1
    For i = 0 To .ListCount - 1
    If .Selected(i) Then Sheets(.List(i)).PrintPreview
    Next
    End With

    UserForm1.Show

    End Sub

    Private Sub imprimer_Click()
    Dim i As Integer
    UserForm1.Hide

    If Application.Dialogs(xlDialogPrinterSetup).Show = False Then
    Exit Sub
    Else
    With ListBox1
    For i = 0 To .ListCount - 1
    If .Selected(i) Then Sheets(.List(i)).PrintOut Copies:=TextBox1.Value
    Next
    End With
    UserForm1.Show
    End If
    End Sub

    Private Sub Label1_Click()

    End Sub

    Private Sub Label2_Click()

    End Sub

    Private Sub Label3_Click()

    End Sub

    Private Sub Label4_Click()

    End Sub

    Private Sub ListBox1_Click()

    For i = 0 To .ListCount - 1
    If ListBox1.Selected(i) Then Sheets(.List(i)).Select
    Next
    End With

    End Sub

    Private Sub ListBox2_Click()

    End Sub

    Private Sub UserForm_Initialize()
    Dim S As Worksheet
    ListBox1.MultiSelect = fmMultiSelectExtended
    For Each S In Worksheets
    If Not S.Name = "Index" Then
    ListBox1.AddItem S.Name
    End If
    Next
    TextBox1 = 0
    End Sub

    Du coup je vois pas où mettre la variable :
    Nom = array("Feuille1","Feuille2","Feuille3")
    0
    1. cs_Le Pivert Messages postés 8437 Statut Contributeur 730
       
      comme ceci:

      Private Sub CommandButton1_Click()
       Dim i As Byte
       Dim nom As String
           'boucle sur les éléments de la listbox
          For i = 0 To ListBox1.ListCount - 1
              If ListBox1.Selected(i) = True Then
            nom = ListBox1.List(i)
            'mettre le code des feuilles à imprimer ici en se servant de la variable nom
        ActiveWorkbook.Sheets(nom).PrintOut
        End If
          Next i
      End Sub


      @+ Le Pivert
      0
  3. hokousai Messages postés 7 Statut Membre
     
    Bonjour Le Pivert,
    Problème résolu.
    Private Sub UserForm_Initialize()
    Dim S As Worksheet
    sh = Array("Index", "Feuil1", "Feuil2")
    ListBox1.MultiSelect = fmMultiSelectExtended
    For Each S In Worksheets
    t = Application.Match(S.Name, sh, 0)
        If IsError(t) Then
            ListBox1.AddItem S.Name
        End If
    Next
    TextBox1 = 0
    End Sub

    Merci encore pour ton aide.
    0