Good afternoon everyone,
I am new to macros and ran into the following error, ""Run time error 1004 - Document not saved. The document may be open, or an error may have been encountered when saving." I created push buttons that export a PDF of all accounts that belong to a certain person. The macro worked great for the majority of the people, but I got the "run time error 1004" on 3 of them. I don't understand the reason for this error, the other macros worked just fine. When I run this macro it exports the majority of the PDFs but runs into the error on the last 4 PDFs its trying to export. The range of values I want to export from is "N135:N153" but it only gets to N149 before the error pops up. I apologize if I'm not the best at describing the problem.
Please find the code used below:
Sub Acosta()
'
' Acosta Macro
' Exports PRxO Savings statements for PBC Acosta to pdf
'
'
Dim sfilename As String
Sheets("Savings Statement").Select
Range("b10").Select
For Each Cell In Sheets("Savings Statement").Range("n135:n153")
Sheets("Savings Statement").Range("b10") = Cell
B = Range("b6")
B = Format(B, "mmmm yyyy")
sfilename = " Savings Statement " & B & " " & Range("b10").Value & " - " & Range("c15").Value
ChDir "F:\Reports\Savings\PDFs\Acosta\"
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
"F:\Reports\Savings\PDFs\Acosta\" & sfilename & ".pdf", _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:= _
False
Next
End Sub
Thank you
I am new to macros and ran into the following error, ""Run time error 1004 - Document not saved. The document may be open, or an error may have been encountered when saving." I created push buttons that export a PDF of all accounts that belong to a certain person. The macro worked great for the majority of the people, but I got the "run time error 1004" on 3 of them. I don't understand the reason for this error, the other macros worked just fine. When I run this macro it exports the majority of the PDFs but runs into the error on the last 4 PDFs its trying to export. The range of values I want to export from is "N135:N153" but it only gets to N149 before the error pops up. I apologize if I'm not the best at describing the problem.
Please find the code used below:
Sub Acosta()
'
' Acosta Macro
' Exports PRxO Savings statements for PBC Acosta to pdf
'
'
Dim sfilename As String
Sheets("Savings Statement").Select
Range("b10").Select
For Each Cell In Sheets("Savings Statement").Range("n135:n153")
Sheets("Savings Statement").Range("b10") = Cell
B = Range("b6")
B = Format(B, "mmmm yyyy")
sfilename = " Savings Statement " & B & " " & Range("b10").Value & " - " & Range("c15").Value
ChDir "F:\Reports\Savings\PDFs\Acosta\"
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
"F:\Reports\Savings\PDFs\Acosta\" & sfilename & ".pdf", _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:= _
False
Next
End Sub
Thank you