|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
- 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 DictAddSheet = Sheets.Add(After:=Worksheets(Worksheets.Count))
- DictAddSheet.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
复制代码 |
|