I am trying to save a sheet as .Csv (Comma delimited) and then rename as .Txt by Cmd.exe (Shell) but not working.
Please help me !!!
Dim MyFolder As String, MyFile As String, MySheetName as String
Dim ShellComand As String
.........
MyFolder = "D:\Revise"
MyFile = Dir(MyFolder & "\*.txt")
Workbooks.OpenText Filename:=MyFolder & "" & MyFile, StartRow:=1, DataType:=xlDelimited, Comma:=True, Tab:=False, Semicolon:=False, Space:=False, Other:=False, FieldInfo:=Array(Array(1, xlTextFormat), Array(2, xlTextFormat), Array(3, xlTextFormat))
MySheetName = Replace(ActiveWorkbook.Name, ".txt", "")
ActiveWorkbook.Sheets(1).Copy After:=Workbooks("Revise.xlsm").Worksheets(Sheets.Count)
ActiveSheet.Name = MySheetName
Worksheets(2).Activate
Application.DisplayAlerts = False
ActiveSheet.SaveAs Filename:=MyFolder & "" & MySheetName + "_Rev_" + Replace(Date, "-", ""), FileFormat:=xlCSV, CreateBackup:=True
'Problem here: .Csv file not saving with same cell format (text)
Application.DisplayAlerts = True
ShellComand = "cmd.exe /k ""cd " & """ & ThisWorkbook.path & """ & " ren *.csv *.txt"""
Shell ShellComand
'Problem here: it can't rename into .txt
Can anybody help me out of this problem ?
Please help me !!!
Dim MyFolder As String, MyFile As String, MySheetName as String
Dim ShellComand As String
.........
MyFolder = "D:\Revise"
MyFile = Dir(MyFolder & "\*.txt")
Workbooks.OpenText Filename:=MyFolder & "" & MyFile, StartRow:=1, DataType:=xlDelimited, Comma:=True, Tab:=False, Semicolon:=False, Space:=False, Other:=False, FieldInfo:=Array(Array(1, xlTextFormat), Array(2, xlTextFormat), Array(3, xlTextFormat))
MySheetName = Replace(ActiveWorkbook.Name, ".txt", "")
ActiveWorkbook.Sheets(1).Copy After:=Workbooks("Revise.xlsm").Worksheets(Sheets.Count)
ActiveSheet.Name = MySheetName
Worksheets(2).Activate
Application.DisplayAlerts = False
ActiveSheet.SaveAs Filename:=MyFolder & "" & MySheetName + "_Rev_" + Replace(Date, "-", ""), FileFormat:=xlCSV, CreateBackup:=True
'Problem here: .Csv file not saving with same cell format (text)
Application.DisplayAlerts = True
ShellComand = "cmd.exe /k ""cd " & """ & ThisWorkbook.path & """ & " ren *.csv *.txt"""
Shell ShellComand
'Problem here: it can't rename into .txt
Can anybody help me out of this problem ?