|
- Sub deldel()
- Dim Sht As Worksheet
- Set Sht = DictAddSheet(ThisWorkbook, "A1")
- Debug.Print Sht.Name
- Set Sht = ForEachAddSheet(ThisWorkbook, "A2")
- Debug.Print Sht.Name
- End Sub
- Function DictAddSheet(Wk As Workbook, Str)
- Dim Dict As Dictionary
- Set Dict = New Dictionary
- Dim Sht As Worksheet
- For Each Sht In Wk.Sheets
- Dict(Sht.Name) = ""
- Next Sht
- If Not Dict.Exists(Str) Then
- Set AddSheet = Sheets.Add(After:=Worksheets(Worksheets.Count))
- AddSheet.Name = Str
- Else
- Set DictAddSheet = Sheets(Str)
- End If
- End Function
- Function ForEachAddSheet(Wk As Workbook, Str)
- Dim Sht As Worksheet
- For Each Sht In Wk.Sheets
- If Sht.Name = Str Then
- Set ForEachAddSheet = Sht
- Exit Function
- End If
- Next Sht
-
- Set ForEachAddSheet = Sheets.Add(After:=Worksheets(Worksheets.Count))
- ForEachAddSheet.Name = Str
- End Function
复制代码
|
|