【发布时间】:2014-01-29 20:48:49
【问题描述】:
我不想对目录进行硬编码,而是想打开一个目录选择器功能,以便用户可以为以下内容选择源文件夹和目标文件夹:
Sub XlsToTxt()
Dim aFile As String
Const SourceFolder = "C:\Users\Documents\PCS\" ' note the backslash at the end of the string
Const targetFolder = "C:\Users\Desktop\PCS Text\" ' note the backslash at the end of the string
Application.DisplayAlerts = False
aFile = Dir(SourceFolder & "*.xls")
Do While aFile <> ""
Workbooks.Open SourceFolder & aFile
ActiveWorkbook.SaveAs targetFolder & Left(aFile, Len(aFile) - 4) _
& ".csv", FileFormat:=xlCSV _
, CreateBackup:=False
ActiveWorkbook.Close
aFile = Dir
Loop
Application.DisplayAlerts = True
End Sub
【问题讨论】:
-
见this 帖子。