帮我写一个关于拆分excel的vba代码
时间: 2023-02-19 14:39:04 浏览: 326
基本的VBA代码如下:
Sub SplitExcel()
Dim xSht As Worksheet
Dim xWb As Workbook
Dim xStrPath As String
Dim xValue As String
Dim I As Long
Dim J As Long
Dim K As Long
On Error Resume Next
xStrPath = Application.DefaultFilePath
If xStrPath = "" Then
xStrPath = Application.UserLibraryPath
End If
xValue = Application.GetOpenFilename("Excel Files (*.xls*),*.xls*", , , , False)
If xValue = "False" Then Exit Sub
Set xWb = Workbooks.Open(xValue)
For I = 1 To xWb.Sheets.Count
Set xSht = xWb.Sheets(I)
xSht.Copy
Set xWb = ActiveWorkbook
xWb.SaveAs Filename:=xStrPath & "\" & xSht.Name & ".xls"
xWb.Close False
Next
xWb.Close False
End Sub
阅读全文