kumar lama
Board Regular
- Joined
- May 20, 2014
- Messages
- 85
Hello,
I am using below code to export Salary Payslip as PDF but i am getting below error while exporting.
after export few Page, i am getting "Run-Time error 1004" (Document not Saved. The Document may be open, or error may have been encountered when saving).
Code is below
Option Explicit
Public Sub SaveAsPdf()
Dim lStart As Long
Dim lEnd As Long
Dim l As Long
Dim rngSlipNumber As Range
With Sheet5
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(" AG4") & "-" & .Range("D8") & " " & .Range(" AR1").Value, _
Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, _
OpenAfterPublish:=False
Next l
End With
End Sub
Thanks in Advance.
I am using below code to export Salary Payslip as PDF but i am getting below error while exporting.
after export few Page, i am getting "Run-Time error 1004" (Document not Saved. The Document may be open, or error may have been encountered when saving).
Code is below
Option Explicit
Public Sub SaveAsPdf()
Dim lStart As Long
Dim lEnd As Long
Dim l As Long
Dim rngSlipNumber As Range
With Sheet5
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(" AG4") & "-" & .Range("D8") & " " & .Range(" AR1").Value, _
Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, _
OpenAfterPublish:=False
Next l
End With
End Sub
Thanks in Advance.