hokousai
05-21-2020, 03:56 PM
Bonjour,
J'ai ce code qui m'a été donné par quelqu'un sur ce forum.
Il vous permet d'enregistrer le contenu d'une ListBox.
Seulement, il le fait pour un seul ListBox.
Comme j'ai plusieurs ListBox, je ne trouve pas de moyen de modifier le code pour ajouter un code comme: ListBox1, ListBox2, etc ...
J'aurais besoin de votre aide
Merci d'avance
Ps: je rejoint un fichier pour vous Pour mieux comprendre.
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
J'ai ce code qui m'a été donné par quelqu'un sur ce forum.
Il vous permet d'enregistrer le contenu d'une ListBox.
Seulement, il le fait pour un seul ListBox.
Comme j'ai plusieurs ListBox, je ne trouve pas de moyen de modifier le code pour ajouter un code comme: ListBox1, ListBox2, etc ...
J'aurais besoin de votre aide
Merci d'avance
Ps: je rejoint un fichier pour vous Pour mieux comprendre.
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