Hello,
I am trying to create a macro that will export a hidden sheet to a *.csv file. I am also trying to have the macro skip any lines where the column A is blank (have not worked on this part of the code yet)
Can anyone see any underlying issues with the below? I keep having an exception on the "Sheets("DataImport").Copy" line with run-time error '1004' - Copy Method of worksheet class failed.
Sub CSVExport()
Dim MyPath As String
Dim MyFileName As String
'The path and file names:
MyPath = ("Settings!B2")
MyFileName = ("R1!E34") & Format(("R1!E35"), "DD.MM.YYYY") & ".CSV"
'Makes sure the path name ends with "\":
If Not Right(MyPath, 1) = "\" Then MyPath = MyPath & "\"
'Makes sure the filename ends with ".csv"
If Not Right(MyFileName, 4) = ".csv" Then MyFileName = MyFileName & ".csv"
'Copies the sheet to a new workbook:
Sheets("DataImport").Copy
'The new workbook becomes Activeworkbook:
With ActiveWorkbook
'Saves the new workbook to given folder / filename:
.SaveAs Filename:= _
MyPath & MyFileName, _
FileFormat:=xlCSV, _
CreateBackup:=False
'Closes the file
.Close False
End With
End Sub
Kind Regards
David
Bookmarks