LeonardSterk
New Member
- Joined
- Mar 21, 2021
- Messages
- 33
- Platform
- Windows
Hi,
An InputBox appears when clicking on the button, when I type a date and click on "OK" it works perfectly.
Except there's also a "Cancel" button, but when you click on Cancel, it still creates the file but without date...
How to cancel the creation of the new sheet with the cancel button?
An InputBox appears when clicking on the button, when I type a date and click on "OK" it works perfectly.
Except there's also a "Cancel" button, but when you click on Cancel, it still creates the file but without date...
How to cancel the creation of the new sheet with the cancel button?
VBA Code:
Sub Export()
Dim PathXLSX As String
Dim NameXLSX As String
PathXLSX = "G:\Companies\"
NameXLSX = "Test" & InputBox("Enter Date") & ".xlsx"
ThisWorkbook.Sheets("Prices").Copy
Application.DisplayAlerts = False
With ActiveWorkbook
.SaveAs Filename:= _
PathXLSX & NameXLSX, _
FileFormat:=51, _
CreateBackup:=False
.Close False
End With
Application.DisplayAlerts = True
MsgBox "The file has been saved at " & PathXLSX & NameXLSX
End Sub