Need help to correct my code:
Sub CommandButton2_Click()
Dim Rw As Long
Dim s As String
s = Range("B8").Value
For Rw = 8 To Present.UsedRange.Rows.Count
If Present.Cells(Rw, 2).Value = "" Then Exit For
Sheet6.Cells(8, 2).Value = Present.Cells(Rw, 2).Value
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
"C:\Payslip\" & s, Quality:=xlQualityStandard, IncludeDocProperties _
:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
s = Range("B8").Value
Next Rw
End Sub
this code prints a payslip to a pdf and automatic filename based on a cell value.
the problem is, the first generated file is fine but after the next loop it overwrites the first generated file. so the payslip content does not match the filename.
Thanks in advance!
Bookmarks