Please Help - Run Time Error 1004 - "Document not saved. The document may be open, or an error may have been encountered when saving."

ColtenW

New Member
Joined
May 11, 2021
Messages
1
Office Version
  1. 365
Platform
  1. Windows
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
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
60,755
Office Version
  1. 365
Platform
  1. Windows
Welcome to the Board!

What is the value in column N (N149 or N150, I presume), when you get that error?
Do you have duplicate values in column N, or illegal characters that cannot be used in file names?
 
Learn Excel from Bill Jelen

Understanding data is crucial, and the easiest place to start is with Microsoft Excel.

Forum statistics

Threads
1,151,589
Messages
5,765,321
Members
425,273
Latest member
tonio909

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
Top