Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

VBA to open .csv file with notepad save as .txt

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

    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"

>Solution :

You could try FileCopy:

FileCopy FilePath & FileName & ".csv", FilePath & FileName & ".txt"
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading