1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【Excel VBA】ブックの名前一覧の辞書化+Exists【関数サンプル】

Last updated at Posted at 2019-08-01
VBA
'-------------------------------
' 関数呼び出し例
'-------------------------------
Private Sub sample()

   Dim nameDic As Object: Set nameDic = CreateObject("Scripting.Dictionary")
    Set nameDic = NameDefinition(ActiveWorkbook)

    '使用例
    Dim ret: ret = IIf(nameDic.Exists("何かの名前"), Range("何かの名前").Value, "")

End Sub

'-------------------------------
' 名前一覧の作成
'-------------------------------
Public Function NameDefinition(wb As Workbook) As Dictionary

    Dim dic As Object: Set dic = CreateObject("Scripting.Dictionary")
    Dim Name: For Each Name In wb.Names
        If dic.Exists(Mid(Name.Name, InStr(Name.Name, "!") + 1)) Then GoTo n
        dic.Add Mid(Name.Name, InStr(Name.Name, "!") + 1), Name
n: Next
    Set NameDefinition = dic
    
End Function
1
0
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?