VBA-excel page Save As PDF Run-Time Error 1004

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.
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
what are you doing with the loop, your not apparently changing the filename, so second iteration will be same name as first
 
Upvote 0
Hello mole999
user-offline.png

I am not export in VBA.
I have use lookup formula in this sheet and AJ1 Is lookup Value AK1=Start No of range , AK2= end No of range.
And "Filename:=.Range(" AG4") & "-" & .Range("D8") & " " & .Range(" AR1").Value, _" AG4=Employees ID, D8=Employees Name, AR1 = Current Date,

Thank you,

 
Upvote 0

Forum statistics

Threads
1,216,084
Messages
6,128,730
Members
449,465
Latest member
TAKLAM

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