提问人:Jack Pennington 提问时间:10/19/2023 更新时间:10/19/2023 访问量:57
VBA 打开带有记事本的 .csv 文件,另存为 .txt
VBA to open .csv file with notepad save as .txt
问:
我需要创建一个宏来打开一个 .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"
答:
2赞
Jack
10/19/2023
#1
您可以尝试:FileCopy
FileCopy FilePath & FileName & ".csv", FilePath & FileName & ".txt"
评论
ActiveWorkbook
Application
ActiveDocument
FileCopy
?