我想使用Excel VBA隐藏" Name1"在名称管理员。你能告诉代码隐藏Name1和Scope Workbook吗?谢谢!
'Can hide Name1 with scope Sheet1
ThisWorkbook.Worksheets("Sheet1").Names("Name1").Visible = False
'Can hide Name1 with scope Sheet2
ThisWorkbook.Worksheets("Sheet2").Names("Name1").Visible = False
'Can hide Name1 with scope Sheet3
ThisWorkbook.Worksheets("Sheet3").Names("Name1").Visible = False
'TODO: I want to hide Name1 with scope Workbook, but failed.
'The code hidden Name1 with scope Sheet1 instead.
ThisWorkbook.Names("Name1").Visible = False
答案 0 :(得分:1)
尝试下面的代码(代码注释中的解释):
Option Explicit
Sub HideNames()
Dim xName As Name
Dim NametoHide As String
NametoHide = "Name1" ' <-- modify to whatever name you want to hide
' loop through all names
For Each xName In ThisWorkbook.Names
If xName.Name = NametoHide Then
xName.Visible = False
End If
Next xName
End Sub