Enregistrer plusieurs ListBox en PDF

  • Initiateur de la discussion Initiateur de la discussion hokousai
  • Date de début Date de début

Boostez vos compétences Excel avec notre communauté !

Rejoignez Excel Downloads, le rendez-vous des passionnés où l'entraide fait la force. Apprenez, échangez, progressez – et tout ça gratuitement ! 👉 Inscrivez-vous maintenant !

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:
- Navigue sans publicité
- Accède à Cléa, notre assistante IA experte Excel... et pas que...
- Profite de fonctionnalités exclusives
Ton soutien permet à Excel Downloads de rester 100% gratuit et de continuer à rassembler les passionnés d'Excel.
Je deviens Supporter XLD

Discussions similaires

Réponses
7
Affichages
330
Réponses
3
Affichages
599
Retour