Private
Sub
Workbook_NewSheet(
ByVal
Sh
As
Object
)
Dim
vntName
As
Variant
, blnOK
As
Boolean
, wks
As
Worksheet, _
objRegEx
As
Object
, objMatch
As
Object
Set
objRegEx = CreateObject(
"VBScript.RegExp"
)
With
objRegEx
.Global =
True
.Pattern =
"[\\\/\:\*\?]"
End
With
blnOK =
True
Do
vntName = Application.InputBox( _
Prompt:=
"Geben Sie einen Namen für das neue Blatt ein:"
, _
Title:=
"Blatt einfügen"
, _
Type:=2)
If
vntName =
False
Then
MsgBox
"Einfügen abgebrochen"
Application.DisplayAlerts =
False
Sh.Delete
Application.DisplayAlerts =
True
Exit
Sub
End
If
If
vntName =
""
Then
MsgBox
"Sie müssen einen gültigen Tabellennamen eingeben."
blnOK =
False
End
If
If
Len(vntName) > 31
Then
MsgBox
"Der eingegebene Name ist zu lang."
blnOK =
False
End
If
For
Each
wks
In
ThisWorkbook.Worksheets
If
wks.Name = vntName
Then
MsgBox
"Der eingegebene Name existiert bereits."
& vbCrLf & _
"Geben Sie einen anderen Namen ein."
blnOK =
False
Exit
For
End
If
Next
wks
Set
objMatch = objRegEx.Execute(
CStr
(vntName))
If
objMatch.Count > 0
Then
MsgBox
"Der Name enthät unzulässige Zeichen (\/:*?)."
blnOK =
False
End
If
Loop
Until
blnOK
Sh.Name = vntName
Set
objMatch =
Nothing
Set
objRegEx =
Nothing
End
Sub