[ 初めての方へ | 一覧(最新更新順) | 全文検索 | 過去ログ ]
『マクロでシート名の変更をする』(すが)
アクティブシートの次のシート名をA1の文字にします。他に同じシート名が
あったり、シート名に使えない文字があったりした時は、何もせずに終了します。
(純丸)(o^-')b
Sub test()
On Error Resume Next
With ActiveSheet
Worksheets(.Index + 1).Name = .Range("A1").Text
End With
End Sub
例:
Sub test()
Dim NewName As String, OldName As String, ws As Workbook
If ActiveSheet.Next Is Nothing then Exit Sub
NewName = ActiveSheet.Range("a1").Text
On Error Resume Next
Set ws = Sheets(NewName)
If Not ws Is Nothing Then
MsgBox "シート名の重複"
Exit Sub
End If
Err.Clear
ActiveSheet.Next.Select
OldName = ActiveSheet.Name
ActiveSheet.Name = NewName
If Err > 0 Then
MsgBox "そのシート名は使用できません"
ActiveSheet.Name = OldName
ExitSub
End If
End Sub
(seiya)
[ 一覧(最新更新順) ]
YukiWiki 1.6.7 Copyright (C) 2000,2001 by Hiroshi Yuki.
Modified by kazu.