Sub CreateWorksheetGenCoding()
Dim ws As Worksheet
Dim wsName As String
Dim sName As String
Dim sNames As String
Dim blnSheetsWanted As Boolean
c00 = "Dim ws"
c01 = " as Worksheet"
c02 = "Set ws"
c03 = " = wb.Sheets("""
c04 = " = Nothing"
sNames = "/"
For i = 1 To ActiveWorkbook.Sheets.Count
Set ws = ActiveWorkbook.Sheets(i)
wsName = ws.Name
ws.Activate
sName = ""
Do sName = Trim(UCase(Application.InputBox( _
IIf(ws.Visible = xlSheetHidden, "隐藏的 - " & vbCr & vbCr, IIf(ws.Visible = xlSheetVeryHidden, "深度隐藏的 - " & vbCr & vbCr, "")) & _
"工作表代码名 = " & wsName, "工作表名称", UCase(wsName), , , , , 2)))
Loop Until sName = "" Or
InStr(sNames, "/" & sName & "/") = 0
sNames = sNames & sName & "/"
Next
blnSheetsWanted = (Len(Trim(Replace(sNames, "/", ""))) > 0)
If blnSheetsWanted Then sNames = Mid(sNames, 2, Len(sNames) - 2)
sq = Split(sNames, "/")
Debug.Print "Sub MyProc()"
' sOutput ""
sOutput "Dim wb As Workbook"
If blnSheetsWanted Then
For i = 0 To UBound(sq)
If Len(sq(i)) Then
sOutput c00 & sq(i) & c01
End If
Next
End If
sOutput ""
sOutput "Set wb = ActiveWorkbook"
If blnSheetsWanted Then
For i = 0 To UBound(sq)
If Len(sq(i)) Then
sOutput c02 & sq(i) & c03 & ActiveWorkbook.Sheets(i + 1).Name & """)"
End If
Next
End If
sOutput ""
sOutput "Application.ScreenUpdating = False"
sOutput "Application.Calculation = xlCalculationManual"
For i = 1 To 10
sOutput ""
Next
sOutput ""
sOutput "Application.ScreenUpdating = True"
sOutput "Application.Calculation = xlCalculationAutomatic"
sOutput ""
sOutput "Set wb = Nothing"
If blnSheetsWanted Then
For i = 0 To UBound(sq)
If Len(sq(i)) Then
sOutput c02 & sq(i) & c04
End If
Next
End If
sOutput ""
sOutput "MsgBox ""代码结束."", vbInformation, ""状态"""
Debug.Print "End Sub"
End Sub
Sub sOutput(s As String)
Debug.Print vbTab & s
End Sub