Created
March 16, 2012 05:27
-
-
Save nobrinskii/2048644 to your computer and use it in GitHub Desktop.
[vba/excel] 新しいシートの名前を取得する
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'------------------------------------------------------------------------------ | |
'新しいシートの名前を取得する | |
'------------------------------------------------------------------------------ | |
'【引数】新しいシートを作成するブック、シート名の初期値 | |
'【戻り値】ブックに重複のないシート名 | |
'【備考】シート名の初期値に重複がある場合は"(X)"を末尾に付ける。 | |
Private Function GetNewSheetName(wbTarget As Workbook, strSheetName As String) As String | |
Dim sheet As Worksheet | |
Dim intNumber As Integer | |
Dim strTmpName As String | |
Dim flag As Boolean | |
strTmpName = strSheetName | |
Do | |
For Each sheet In wbTarget.Worksheets | |
If sheet.Name = strTmpName Then | |
flag = True | |
Exit For | |
End If | |
Next sheet | |
If flag = True Then | |
intNumber = intNumber + 1 | |
strTmpName = strSheetName & "(" & CStr(intNumber) & ")" | |
flag = False | |
Else | |
Exit Do | |
End If | |
Loop | |
GetNewSheetName = strTmpName | |
End Function |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment