zoukankan      html  css  js  c++  java
  • 20181013xlVba年级报表拆分为班级报表

    '年级报表拆分为班级报表
    Public Sub CreateClassReport()
        Application.DisplayAlerts = False
        
        Dim Wb As Workbook
        Dim OneSht As Worksheet
        Dim NewWb As Workbook
        Dim FolderPath As String
        Dim FilePath As String
        Dim FileName As String
        
        Dim Num
        
        Dim Dic As Object
        Set Wb = Application.ThisWorkbook
        Set Dic = CreateObject("Scripting.Dictionary")
        FolderPath = Wb.Path & ""
        
        For Each OneSht In Wb.Worksheets
            Num = RegGet(OneSht.Name, "(d*)")
            If Num <> "" Then
                Dic(Num) = ""
            End If
        Next OneSht
        For Each Num In Dic.keys
            FileName = Num & "班级报表.xlsx"
            On Error Resume Next
            Application.Workbooks(FileName).Close True
            On Error GoTo 0
            
            FilePath = FolderPath & FileName
            
            On Error Resume Next
            Kill FilePath
            On Error GoTo 0
            
            Set NewWb = Application.Workbooks.Add
            NewWb.SaveAs Num & ".xlsx"
            For Each OneSht In Wb.Worksheets
                If RegGet(OneSht.Name, "(d*)") = "" Or RegGet(OneSht.Name, "(d*)") = Num Then
                    OneSht.Copy after:=NewWb.Worksheets(NewWb.Worksheets.Count)
                End If
            Next OneSht
            NewWb.Worksheets(1).Delete
            NewWb.Save
            NewWb.Close True
        Next Num
        
        Set Dic = Nothing
        Set Wb = Nothing
        Set NewWb = Nothing
        Set OneSht = Nothing
        
        Application.ScreenUpdating = True
        
    End Sub
    
    Public Function RegGet(ByVal OrgText As String, ByVal Pattern As String) As String
        Dim Regex As Object
        Dim Mh As Object
        Set Regex = CreateObject("VBScript.RegExp")
        With Regex
            .Global = True
            .Pattern = Pattern
        End With
        If Regex.test(OrgText) Then
            Set Mh = Regex.Execute(OrgText)
            RegGet = Mh.Item(0).submatches(0)
        Else
            RegGet = ""
        End If
        Set Regex = Nothing
    End Function
    

      

  • 相关阅读:
    【UVa 1592】Database
    【UVa 400】Unix ls
    【UVa 136】Ugly Numbers
    【UVa 540】Team Queue
    【Uva 12096】The SetStack Computer
    【POJ 1050】To the Max
    【UVa 156】Ananagrams
    【UVa 10815】Andy's First Dictionary
    [HNOI/AHOI2018]转盘
    CF46F Hercule Poirot Problem
  • 原文地址:https://www.cnblogs.com/nextseven/p/9783924.html
Copyright © 2011-2022 走看看