vba

作者: maocy | 来源:发表于2017-06-27 14:36 被阅读0次

批量转csv

http://blog.sina.com.cn/s/blog_70fa8d2a0102vs30.html

Sub SaveToCSVs()
    Dim fDir As String
    Dim wB As Workbook
    Dim wS As Worksheet
    Dim fPath As String
    Dim sPath As String
    fPath = "C:\Users\ms-off1\Desktop\temp\"
    sPath = "C:\Users\ms-off1\Desktop\temp\"
    fDir = Dir(fPath)
    Do While (fDir <> "")
        If Right(fDir, 4) = ".xls" Or Right(fDir, 5) = ".xlsx" Then
            On Error Resume Next
            Set wB = Workbooks.Open(fPath & fDir)
            'MsgBox (wB.Name)
            For Each wS In wB.Sheets
                wS.SaveAs sPath & wB.Name & ".csv", xlCSV
            Next wS
            wB.Close False
            Set wB = Nothing
        End If
        fDir = Dir
        On Error GoTo 0
    Loop
End Sub

相关文章

网友评论

      本文标题:vba

      本文链接:https://www.haomeiwen.com/subject/bolecxtx.html