I'm new at macros so please bare with me.
The below code should save a version of the file in CSV format with a name equal to a cell value.
Sometimes it works, sometimes it doesn't. I added what I think is a check to see if the file exists. The macro acts as if the file is there and gives me my msgbox. When checking the folder in explorer, it doesn't show. When I try the macro again, Excel even asks if a want to replace the existing file. Even though the file doesn't show. What is happening?
Sub ExportCSCSV()
'
' ExportCSCSV Macro
'
Dim MyFile As String
MyFile = Range("A3").Value & ".csv"
Dim Loc As String
Loc = "\\JMAS\Share\CSV_FILES\Cost Sheet\" & MyFile
ChDir "\\JMAS\Share\CSV_FILES\Cost Sheet"
ActiveWorkbook.SaveAs Filename:=MyFile, _
FileFormat:=xlCSV, CreateBackup:=False
If Loc <> "" Then MsgBox (MyFile & " has been successfully saved to \\JMAS\Share\CSV_FILES\Cost Sheet")
ActiveWorkbook.Close
'
End Sub
Bookmarks