我有一个脚本来替换外部源提供的文件中的定界符。该脚本可以正常运行,但我想添加使用对话框选择文件的功能,并在替换后使用另存为对话框将文件另存为其他功能。
我尝试了这里和MSDN文档中发现的几种不同方法,并且打开了框,但是没有替换数据,也没有保存文件。也许我的搜寻字词不正确。我过去从未使用过对话框:(
Sub RosterDelimiters_FindReplace()
Dim TextFile As Integer
Dim FilePath As String
Dim FileContent As String
FilePath = "C:\ReplaceText\Roster.txt"
TextFile = FreeFile
Open FilePath For Input As TextFile
FileContent = Input(LOF(TextFile), TextFile)
Close TextFile
FileContent = Replace(FileContent, ";+;", ",")
FileContent = Replace(FileContent, ";", ",")
TextFile = FreeFile
Open FilePath For Output As TextFile
Print #TextFile, FileContent
Close TextFile
End Sub
伪代码中首选的结果操作:
Sub
Dialog Box Opens
TextFile is selected
Replacements Run
Save As Box Opens
File is Named and Saved Wherever
End Sub