自动将Excel 2007转换为Excel 97-2003工作簿

时间:2014-09-09 15:27:35

标签: java excel dos

我需要将Excel 2007转换为Excel 97-2003工作簿,

我通过打开excel手动执行此操作并保存为Excel 97-2003工作簿
但我希望它是自动化的。 是否可能

1 个答案:

答案 0 :(得分:1)

将您要转换的文件的文件规范放在 Sheet1 A 列中,如下所示:

enter image description here

然后运行这个小的 VBA 宏:

Sub asdf()
    Dim s As String, N As Long, i As Long
    Sheets("Sheet1").Activate
    N = Cells(Rows.Count, "A").End(xlUp).Row
    For i = 1 To N
        s = Cells(i, 1).Value
        Workbooks.Open Filename:=s
        s = Replace(s, ".xlsx", ".xls")
        s = Replace(s, "xlsm", ".xls")
        ActiveWorkbook.SaveAs Filename:=s, _
            FileFormat:=xlExcel8, Password:="", _
            WriteResPassword:="", _
            ReadOnlyRecommended:=False, _
            CreateBackup:=False
        ActiveWorkbook.Close
    Next i
End Sub