troubleshooting Question

Visual basic check if file exists

Avatar of Euro5
Euro5Flag for United States of America asked on
VBAMicrosoft ExcelMicrosoft Office
5 Comments1 Solution22 ViewsLast Modified:
This code works only if the file does not already exist.
Can I add something to overwrite?

Sub PrintSelectionToPDFEDS()
Dim invoiceRng As Range
Dim pdfile As String
'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, _
End Sub

Open in new window

Join our community to see this answer!
Unlock 1 Answer and 5 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros