ws.SaveAs "U:\TL\PV\CSV\test.csv", xlCSV
ActiveWorkbook.Close False
<!-- / message -->
hi what is wrong with this code? i have set ws as Sheet2
With ws
.Copy.SaveAs Filename:= _
"U:\TL\PV\CSV\test.csv", FileFormat:=xlCSV, _
CreateBackup:=False
.Close = False
End With
should work, if it is true.
That's impposible.
It doesn't matter.
With or witout "With" statement, once you set the reference to Sheet2, it will always refer to that object.
You are saying
Sheets("sheet2").SaveAs ....
is saving Sheet1, that is impossible.
Sub csv()
Dim ws As Worksheet
Set ws = ThisWorkbook.Worksheets("Sheet2")
ws.SaveAs ThisWorkbook.Path & "\xxxtest.csv", FileFormat:=xlCSV '"U:\TL\PV\CSV\test.csv", xlCSV
ActiveWorkbook.Close False
End Sub