请使用记事本打开.csv文件并保存为.txt

oiopk7p5  于 6个月前  发布在  其他
关注(0)|答案(1)|浏览(80)

我需要创建一个宏,将打开一个.csv文件,但打开它在记事本(这保留了格式,我需要),然后保存这个打开的记事本作为一个.txt文件。
我现在的代码将根据需要在记事本中打开.csv文件。但我不能保存是作为一个具有相同文件名的.txt文件。
有什么建议吗?

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"

字符串

yvgpqqbh

yvgpqqbh1#

你可以试试FileCopy

FileCopy FilePath & FileName & ".csv", FilePath & FileName & ".txt"

字符串

相关问题