Arie Bos
Board Regular
- Joined
- Mar 25, 2016
- Messages
- 224
- Office Version
- 365
- Platform
- Windows
I use the following code to save all sheets with names starting with "LP" as separate pdf files:
2 questions:
1. The code halts after successfully saving the first report as "B-II [17_10] LP01. John Doe" (where 17_10 comes out of cell name 'SelectedMonth', LP01 comes of cell Z11 and John Doe come out of cell I4). The error which pops up is:"run time error 1004: Document is not saved. The document may be open, or an error may have been encountered when saving".
2. In the path definition the pdf's must be saved into the correct month folder. So every month I create a folder under with the new month name so, 17_10, 17_11 etc. Then I change this month number in the path above (Fname = ...). Of course this is not much work, but for elegancy, can this be done by the macro by reading the month number out of "SelectedMonth" ?
Thank you Excelleers!
Arie
Code:
Sub Save_all_Reports()
Dim Fname As String
Dim Sht As Worksheet
For Each Sht In ActiveWorkbook.Sheets
If UCase(Left(Sht.Name, 2)) = "LP" Then 'Only include sheets beginning LP
Fname = "C:\Users\Arie\B-II\Monthly Reports\17_10\" & "B-II" & " [" & Sheets("START").Range("SelectedMonth") & "] " & Sht.Range("Z11") & ". " & Sht.Range("i4") & ".pdf"
Sht.ExportAsFixedFormat 0, Fname
End If
Next Sht
End Sub
2 questions:
1. The code halts after successfully saving the first report as "B-II [17_10] LP01. John Doe" (where 17_10 comes out of cell name 'SelectedMonth', LP01 comes of cell Z11 and John Doe come out of cell I4). The error which pops up is:"run time error 1004: Document is not saved. The document may be open, or an error may have been encountered when saving".
2. In the path definition the pdf's must be saved into the correct month folder. So every month I create a folder under with the new month name so, 17_10, 17_11 etc. Then I change this month number in the path above (Fname = ...). Of course this is not much work, but for elegancy, can this be done by the macro by reading the month number out of "SelectedMonth" ?
Thank you Excelleers!
Arie