Enregistrer plusieurs ListBox en PDF

hokousai

XLDnaute Nouveau
Hello,
I have this code that was given to me by someone on this forum.

VB:
Private Sub Enregistrer_1_seul_PDF_Click()
    Dim i As Long
    Dim k As Long
    Dim varrSelected() As Variant
    Dim varrToSave  As Variant
    Dim shActiv     As Object

    k = -1
    Application.ScreenUpdating = False
   
    For i = 0 To ListBox2.ListCount - 1
        If ListBox2.Selected(i) Then
            k = k + 1
            ReDim Preserve varrSelected(0 To 1, 0 To k)
            varrToSave = varrToSave & "/" & ListBox2.List(i)
            varrSelected(0, k) = ListBox2.List(i)
            varrSelected(1, k) = ThisWorkbook.Sheets(varrSelected(0, k)).Visible
            ThisWorkbook.Sheets(varrSelected(0, k)).Visible = xlSheetVisible
        End If
    Next i
    If k > -1 Then
        Set shActiv = ActiveSheet
        varrToSave = Mid(varrToSave, 2)
        varrToSave = Split(varrToSave, "/")
        ThisWorkbook.Sheets(varrToSave).Select
        'Feuil2 is a CodeName of "Parametres" sheet
        ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:="O:\" & Feuil2.Range("C2").Value & ".pdf"
        shActiv.Select
        For i = 0 To UBound(varrSelected, 2)
            ThisWorkbook.Sheets(varrSelected(0, i)).Visible = varrSelected(1, i)
        Next i
       
        MsgBox "Selected sheets were saved in a PDF file.", vbInformation
    End If
   
    Application.ScreenUpdating = True
End Sub
It allows you to save the contents of a ListBox.
Only it does that for a single ListBox.
Since I have several ListBoxes, I can't find a way to modify the code to add a code like: ListBox1, ListBox2, etc. ...
I would need your help
Thank you in advance
Ps: I am attaching a file for you to better understand.
 
Dernière édition:

Discussions similaires

Réponses
4
Affichages
191
Réponses
11
Affichages
280

Statistiques des forums

Discussions
312 084
Messages
2 085 194
Membres
102 811
dernier inscrit
caroline29260