vincentchrisnata
New Member
- Joined
- Feb 10, 2022
- Messages
- 5
- Office Version
- 365
- 2013
- Platform
- Windows
Hello,
I have a problem on the dir function, as i run the code, it does nothing. I want to prompt a message asking to overwrite file if the file already exists in the directory.
Thanks before.
I have a problem on the dir function, as i run the code, it does nothing. I want to prompt a message asking to overwrite file if the file already exists in the directory.
Thanks before.
VBA Code:
Sub SavePDF_Cost()
Dim DocPath As String
Dim DefName As String
Dim EmpID As String
Dim DocName As String
DocPath = "X:\Cost"
DefName = "Cost."
EmpID = Range("A2").Value
DocName = DefName & EmpID
If Dir(DocPath & DocName) <> vbNullString Then
If MsgBox(DocName & " already exists!" & vbNewLine & "Do you want to overwrite it?", vbExclamation + vbYesNo) = vbYes Then
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=DocPath & DocName, Quality:=xlQualityStandard, _
IncludeDocProperties:=False, IgnorePrintAreas:=False, OpenAfterPublish:=True
MsgBox "The File has been saved!"
End If
End If
End Sub