Arie Bos
Board Regular
- Joined
- Mar 25, 2016
- Messages
- 224
- Office Version
- 365
- Platform
- Windows
I have a workbook with 20 sheets with names starting with "LP", so LP01, LP02, LP03 ...LP20. There are also 4 other sheets with other names, not in the LP range.
I have the code below to save all sheets as PDF with names as follows: "B-II [18_05] LP01. John.pdf", "B-II [18_05] LP02. Peter.pdf", and so on until LP20.
Sht.Range("Z11") retrieves the sheet number (LP01, LP02) in cell I4, and Sht.Range("I4") retrieves the name (John, Peter).
The code starts OK, and creates the first pdf in the right location for LP01, John, but then hangs at "Sht.ExportAsFixedFormat 0, Fname:" with error 1004.
Why would the code stop after the first pdf is created successfully?
I have the code below to save all sheets as PDF with names as follows: "B-II [18_05] LP01. John.pdf", "B-II [18_05] LP02. Peter.pdf", and so on until LP20.
Sht.Range("Z11") retrieves the sheet number (LP01, LP02) in cell I4, and Sht.Range("I4") retrieves the name (John, Peter).
The code starts OK, and creates the first pdf in the right location for LP01, John, but then hangs at "Sht.ExportAsFixedFormat 0, Fname:" with error 1004.
Why would the code stop after the first pdf is created successfully?
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
Fname = "C:\Users\User\Dropbox\BCM\BFO\B-II\Monthly Reports\18_05\" & "B-II [18_05] " & Sht.Range("Z11") & ". " & Sht.Range("i4") & ".pdf"
Sht.ExportAsFixedFormat 0, Fname
End If
Next Sht
End Sub