sharky12345
Well-known Member
- Joined
- Aug 5, 2010
- Messages
- 3,422
- Office Version
- 2016
- Platform
- Windows
I'm using this to loop through the selected items in a multi-select Listbox on a userform;
What I need it to do is create a pdf file for each selected item - it does the first one it finds but not any after that. Can someone please show me where I am going wrong?
Code:
With Me.ListBox1 For i = 0 To .ListCount - 1
If .Selected(i) Then
Application.ScreenUpdating = False
Sheet2.Activate
Sheet2.Visible = xlSheetVisible
Sheet2.Range("D10").Value = .List(i, 0) & " " & .List(i, 1)
Sheet2.Range("D11").Value = "Unit"
Sheet2.Range("D12").Value = .List(i, 2)
'Requal course
If ComboType = "Requalification" Then
CourseDate = Format(TextDate1, "dd mmm yyyy")
Sheet2.Range("D15").Value = "REQUALIFICATION"
Sheet2.Range("D16").Value = "OPERATOR"
Sheet2.Range("D18").Value = Format(TextDate1, "dd mmmm yyyy")
Sheet2.Range("D20").Value = ComboInst1.Text
Sheet2.Range("D23").Value = ComboInst2.Text
FName = "Authority - " & Sheet2.Range("D10").Value & ".pdf"
path = ThisWorkBook.path & "\Courses\Requal Courses\" & CourseDate & "\ " & FName
Sheet2.ExportAsFixedFormat Type:=xlTypePDF, FileName:=path, IgnorePrintAreas:=False, openafterpublish:=False
End If
'Initial course
If ComboType = "Initial" Then
CourseDate = Format(TextDate1, "dd mmm yyyy")
Sheet2.Range("D15").Value = "INITIAL"
Sheet2.Range("D16").Value = "OPERATOR"
Sheet2.Range("D18").Value = Format(TextDate2, "dd mmmm yyyy")
Sheet2.Range("D20").Value = ComboInst1.Text
Sheet2.Range("D23").Value = ComboInst2.Text
FName = "Authority - " & Sheet2.Range("D10").Value & ".pdf"
path = ThisWorkBook.path & "\Courses\Initial Courses\" & CourseDate & "\ " & FName
Sheet2.ExportAsFixedFormat Type:=xlTypePDF, FileName:=path, IgnorePrintAreas:=False, openafterpublish:=False
End If
End If
Next i
End With
What I need it to do is create a pdf file for each selected item - it does the first one it finds but not any after that. Can someone please show me where I am going wrong?