Hi Raj Kumar,
Welcome to ExcelFox!
Try
Code:
Sub SaveAsCSV()
Dim CSVFileName As String
Dim wbkActive As Workbook
Dim wbkNew As Workbook
Dim i As Long
Dim blnFolderExists As Boolean
Dim FilePath As String
FilePath = "C:\Users\RajKum\My Documents\Converted\"
With Application
.ScreenUpdating = 0
.DisplayAlerts = 0
End With
Set wbkActive = ThisWorkbook
Set wbkNew = Workbooks.Add
wbkNew.Worksheets(1).Range("a1:c499").Value = wbkActive.Worksheets(2).Range("a2:c500").Value
CSVFileName = Application.InputBox("Enter the New CSV File Name", Type:=2)
Application.DisplayAlerts = 0
For i = wbkNew.Worksheets.Count To 2 Step -1
wbkNew.Worksheets(i).Delete
Next
blnFolderExists = CBool(Len(Dir(FilePath, vbDirectory)))
If Not blnFolderExists Then
MkDir FilePath
End If
If Right$(FilePath, 1) <> "\" Then FilePath = FilePath & Application.PathSeparator
wbkNew.SaveAs Filename:=FilePath & CSVFileName, FileFormat:=6 '"CSV"
wbkNew.Close
Set wbkNew = Nothing
Set wbkActive = Nothing
With Application
.DisplayAlerts = 1
.ScreenUpdating = 1
End With
End Sub
Bookmarks