VBA Code for Payslip Save As PDF

kumar lama

Board Regular
Joined
May 20, 2014
Messages
85
Hello All,
I am looking code for save as PDF in excel 2013,
i have one sheet (Summery) Calculation all data. other Sheet (Payslip). i am using Lookup formula to get data from Summary.
i am using Below code for printing all Payslip in one time. same like that i want Save AS code. Please help me. AJ1 Is lookup Value. and Ak1= Start Number, AK2= End Number(Or last Row of Payroll)

Public Sub PrintSlips()
Dim lStart As Long
Dim lEnd As Long
Dim l As Long
Dim rngSlipNumber As Range


Set rngSlipNumber = Sheet5.Range("AJ1")
lStart = Sheet5.Range("Ak1") ' indicates starting Sr num
lEnd = Sheet5.Range("Ak2") ' indicates ending Sr num


For l = lStart To lEnd
rngSlipNumber.Value2 = l
rngSlipNumber.Parent.PrintOut
Next l
End Sub

D8 Cell Has employees Name,
Also its better i can save file every name.


Thank in Advance
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Try this

Code:
Option Explicit






Public Sub PrintSlips()
    Dim lStart As Long
    Dim lEnd As Long
    Dim l As Long
    Dim rngSlipNumber As Range


    With Sheet1
        Set rngSlipNumber = .Range("AJ1")
        lStart = .Range("Ak1")    ' indicates starting Sr num
        lEnd = .Range("Ak2")      ' indicates ending Sr num




        For l = lStart To lEnd
            rngSlipNumber.Value = l
            .ExportAsFixedFormat Type:=xlTypePDF, Filename:=.Range("D8").Value, _
                                 Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, _
                                 OpenAfterPublish:=False
        Next l
    End With
End Sub
 
Upvote 0
Thanks alot Mr. royUk but its help me what i asked but i want more something.

Is it possible to do like Filename:=.Range(Mr."D8"&"E8").Value, i want use Mr and first name and second Name using Code. Like D8=A & E8=B, File need to save As Mr. AB

As this code file are saving inside Document folder, Is it possible to make other destination?
thank you, i hope you have answer for this also.
 
Upvote 0
Mr. royUk I solved This Is it possible to do like Filename:=.Range(Mr."D8"&"E8").Value, i want use Mr and first name and second Name using Code. Like D8=A & E8=B, File need to save As Mr. AB :)
 
Upvote 0
I'm not sure if you have solved this or not

Code:
[COLOR=#333333]Filename:="Mr. " &.Range("D8").Value  & " " & .Range("E8").Value,[/COLOR]
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,917
Members
452,366
Latest member
TePunaBloke

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top