Skip to content

Instantly share code, notes, and snippets.

@yanping
Created November 8, 2012 16:20
Show Gist options
  • Save yanping/4039836 to your computer and use it in GitHub Desktop.
Save yanping/4039836 to your computer and use it in GitHub Desktop.
批量转换xls为csv的VBA代码
'批量转换文件夹中的xls为csv
'地址 http://www.cnblogs.com/snippet/archive/2010/07/06/xls2csv.html
Option Explicit
Sub covertFile(ByRef sFilename As String)
Dim oWorkbook As Workbook
Set oWorkbook = Workbooks.Open(Filename:=sFilename)
oWorkbook.SaveAs Filename:=sFilename & ".csv", FileFormat:= _
xlCSV, CreateBackup:=False
oWorkbook.Close False
End Sub
Sub covertFiles()
Dim sPath As String
Dim sDir As String
sPath = "K:\Desktop\List"
sDir = Dir(sPath & "\*.xls")
While Len(sDir)
Debug.Print sDir
covertFile sPath & "\" & sDir
sDir = Dir
Wend
End Sub
@yanping
Copy link
Author

yanping commented Nov 8, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment