|
我电脑用的excel2016,所以只能给你封装个2016的了,经测试可以用。请试用- Private Sub Form_Load()
- Dim xlApp As Object, wb As Workbook
- On Error GoTo GUANBI:
- Set xlApp = CreateObject("Excel.Application")
- FileName = xlApp.GetOpenFilename("所有文件(*.*),", , "请选择文件")
- If Dir(FileName) = "" Then
- msg = MsgBox("必须选择一个要拆分的文件", vbCritical, "错误")
- Else
- Set wb = xlApp.Workbooks.Open(FileName)
- Dim sht As Worksheet
- xlApp.ScreenUpdating = False
- ipath = wb.Path & ""
- For Each sht In wb.Sheets
- sht.Copy
- xlApp.ActiveWorkbook.SaveAs ipath & sht.Name & ".xlsx"
- xlApp.ActiveWorkbook.Close
- Next
- xlApp.ScreenUpdating = True
- wb.Close
- End If
- GUANBI:
- If Err.Number <> 0 Then
- MsgBox "执行过程中遇到了未知的错误", vbOKOnly, "错误"
- Else
- MsgBox "完成", vbOKOnly, ""
- End If
- Set xlApp = Nothing
- Unload Me
- End Sub
复制代码
|
评分
-
1
查看全部评分
-
|