Euro5
asked on
Visual basic check if file exists
This code works only if the file does not already exist.
Can I add something to overwrite?
Can I add something to overwrite?
Sub PrintSelectionToPDFEDS()
Dim invoiceRng As Range
Dim pdfile As String
Worksheets("Scorecard").Activate
'Setting range to be printed
Set invoiceRng = Range("A1:J101")
'setting file name with a time stamp.
strfile = "_EDS" & ".pdf"
'setting the fulli qualified name. The resultent pdf will be saved where the main file exists.
pdfile = ThisWorkbook.path & "/Operation Scorecard" & strfile
invoiceRng.ExportAsFixedFormat Type:=xlTypePDF, _
filename:=pdfile, _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=False
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
While I try to figure out why, uncomment line 5 which I commented for my original testing.
Try changing to this
strFile = Format(Now, " mm-dd-ss") & "_EDS" & ".pdf"
Your previous code was generating a filename that contained forward slashes like this:
C:\aatmpI\Operation Scorecard 06/27/45_EDS.pdf
rberke (aka unclebob)
strFile = Format(Now, " mm-dd-ss") & "_EDS" & ".pdf"
Your previous code was generating a filename that contained forward slashes like this:
C:\aatmpI\Operation Scorecard 06/27/45_EDS.pdf
rberke (aka unclebob)
Open in new window