I need to create a macro that will open a .csv file, but open it in notepad (this preserves the formatting that I require) then save this open notepad as a .txt file.
My current code will open the .csv file in notepad as required. But I cannot save is as a .txt file with the same FileName.
Any suggestions?
Dim FileName As String
Dim FilePath As String
FileName = "file1"
FilePath = "C:\folder_structure\"
'This opens the .csv file in notepad and works
Shell "notepad.exe " & FilePath & FileName & ".csv", vbNormalFocus
'***** The comments below contain the approaches I have tried but none work *****
'ActiveWorkbook.SaveAs FileName:=FilePath & FileName & ".txt.", FileFormat:=xlCSVWindows
'Application.SaveAs fileName:=FilePath & fileName & ".txt.", FileFormat:=xlCSVWindows
'ActiveDocument.SaveAs fileName:=FilePath & fileName & ".txt.", FileFormat:=xlCSVWindows
'in essense I want this
open notepad .SaveAs FilePath & FileName & ".txt"
You could try FileCopy
:
FileCopy FilePath & FileName & ".csv", FilePath & FileName & ".txt"