|
楼主 |
发表于 2020-9-9 17:07
|
显示全部楼层
本帖最后由 3190496160 于 2020-9-11 07:34 编辑
Private Sub CommandButton1_Click()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Dim ar()
ReDim ar(1 To 10000)
Dim wb As Workbook
With ListBox1
For i = 0 To .ListCount - 1
If .Selected(i) = True Then
m = m + 1
ar(m) = .List(i, 0)
End If
Next i
End With
If m = "" Then MsgBox "请选择需要拆分的工作表": Exit Sub
If OptionButton2 = False And OptionButton3 = False Then MsgBox "请选择拆分类型": Exit Sub
If OptionButton2 = True Then
For i = 1 To m
ww.Worksheets(ar(i)).Copy
Set wb = ActiveWorkbook
wb.SaveAs Filename:=ThisWorkbook.Path & "\拆分文件\" & ar(i)
wb.Close
Next i
ElseIf OptionButton3 = True Then
Application.SheetsInNewWorkbook = 1
Set wb = Workbooks.Add
wb.Worksheets(1).Name = "ww"
For i = 1 To m
ww.Worksheets(ar(i)).Copy after:=wb.Worksheets(wb.Worksheets.Count)
wb.Worksheets(wb.Worksheets.Count).Name = ar(i)
Next i
wb.Worksheets(1).Delete
wb.SaveAs Filename:=ThisWorkbook.Path & "\拆分文件\拆分文件" & Format(Date, "yyyymmdd")
wb.Close
End If
ww.Close False
MsgBox "数据拆分完毕!"
End
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
Private Sub CommandButton2_Click()
End
End Sub
Private Sub CommandButton3_Click() '浏览选择文件
Set d = CreateObject("scripting.dictionary")
filenames = Application.GetOpenFilename("所有文件 (*.*),", , "请选择文件")
If filenames = False Then GoTo 100
Set ww = Workbooks.Open(filenames)
For Each sh In ww.Worksheets
d(sh.Name) = ""
Next sh
Me.ListBox1.List = d.keys
100:
End Sub
Private Sub CommandButton4_Click()
With ListBox1
For i = 0 To .ListCount - 1
.Selected(i) = True
Next i
End With
End Sub
Private Sub CommandButton5_Click()
With ListBox1
For i = 0 To .ListCount - 1
.Selected(i) = False
Next i
End With
End Sub
|
评分
-
2
查看全部评分
-
|