jondavis1987
Active Member
- Joined
- Dec 31, 2015
- Messages
- 443
- Office Version
- 2019
- Platform
- Windows
I have a vba to create a report in PDF format. Sometimes I'll need to create up to 4 pdf reports of the same product. When this happens the first report will essentially look like this. Product 1 11-2-20. This name is decided from formulas in cells and the vba uses the cell to name it. If i'm on report number 2 it would get saved as Product 1 11-2-20 #2. This would happen up to Product 1 11-2-20 #4. How would I modify this to see if the file exists and then to add the correct number to it?
VBA Code:
' Export source workbook to PDF
With srcWB
fName = srcWB.Sheets("A").Range("A!F19").Value
Sheets(Array("A", "Sheet2")).Select
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
"C:\Users\" & Environ("username") & "\Dropbox\Quality Control\Asphalt\Asphalt Reports\" & fName, _
openafterpublish:=True, ignoreprintareas:=False
End With
srcWB.Sheets("A").Select
Exit Sub