Skip to content

Instantly share code, notes, and snippets.

@YujiFukami
Created August 18, 2023 02:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save YujiFukami/8116b1bb0f959b16345fe55124ce4d9c to your computer and use it in GitHub Desktop.
Save YujiFukami/8116b1bb0f959b16345fe55124ce4d9c to your computer and use it in GitHub Desktop.
Option Explicit
Private Pri_List名前定義 As Variant
Private Sub cmd消去_Click()
Call S__名前定義消去
End Sub
Private Sub S__名前定義消去()
Dim Row As Long: Row = list一覧.ListIndex + 1
If Row = 0 Then Exit Sub
Dim CellAddress As String: CellAddress = Pri_List名前定義(Row, 5)
Dim Cell As Range: Set Cell = Range(CellAddress)
Dim Sheet As Worksheet: Set Sheet = Cell.Parent
Dim Book As Workbook: Set Book = Sheet.Parent
Dim Name As Name
Dim StrName As String: StrName = Pri_List名前定義(Row, 3)
For Each Name In Sheet.Names
If Name.Name = StrName Then
Name.Delete
Exit For
End If
Next
For Each Name In Book.Names
If Name.Name = StrName Then
Name.Delete
Exit For
End If
Next
Call S__初期設定(True)
If list一覧.ListCount = 0 Then
'何もしない
ElseIf list一覧.ListCount = 1 Then
list一覧.ListIndex = 0
ElseIf Row = 1 Then
list一覧.ListIndex = 0
ElseIf list一覧.ListCount - 1 >= Row - 1 Then
If Row - 1 >= 1 Then
list一覧.ListIndex = Row - 1
End If
End If
End Sub
Private Sub cmd閉じる_Click()
Unload Me
End Sub
Private Sub list一覧_Click()
'選択したものを反映
Dim Row As Long: Row = list一覧.ListIndex + 1
Dim CellAddress As String: CellAddress = Pri_List名前定義(Row, 5)
Dim Cell As Range: Set Cell = Range(CellAddress)
Cell.Select
End Sub
'※※※※※※※※※※※※※※※※※※※※※※※※※※
'初期設定
Private Function S__初期設定(Optional Opt_非表示は非表示 As Boolean = True) As Boolean
'アクティブシート内の名前定義一覧を取得して、list一覧に表示する。
'名前定義が1つもなかったらFalseを返す
Dim List_名前定義 As Variant: List_名前定義 = GetNamesInActiveSheet
If IsEmpty(List_名前定義) = True Then
list一覧.Clear
MsgBox "名前定義はありませんでした", vbExclamation
Exit Function
End If
If Opt_非表示は非表示 = True Then
List_名前定義 = FilterArray2D(Array2D:=List_名前定義, Filter_:=True, Col:=7, Condition:=vbと等しい)
End If
If IsEmpty(List_名前定義) = True Then
list一覧.Clear
MsgBox "名前定義はありませんでした", vbExclamation
Exit Function
End If
Dim I As Long
Dim N As Long: N = UBound(List_名前定義, 1)
Dim Output As Variant: ReDim Output(1 To N)
For I = 1 To N
If List_名前定義(I, 1) = "Worksheet" Then
Output(I) = "S " & List_名前定義(I, 4)
ElseIf List_名前定義(I, 1) = "Workbook" Then
Output(I) = "B " & List_名前定義(I, 4)
End If
Next
Pri_List名前定義 = List_名前定義
list一覧.List = Output
S__初期設定 = True
End Function
Private Sub list一覧_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
If KeyCode = 46 Then
Call S__名前定義消去
End If
End Sub
Private Sub UserForm_Initialize()
If S__初期設定(True) = False Then
Call cmd閉じる_Click
End If
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment