Public
Sub
CreateCommandBar()
Dim
objCommandBar
As
CommandBar
Dim
objCommandBarButton
As
CommandBarButton
Dim
objName
As
Name
Dim
lngIndex
As
Long
Call
DeleteCommandBar
Set
objCommandBar = CommandBars.Add(Name:=CONTEXT_MENU, _
Position:=msoBarPopup, Temporary:=
True
)
For
lngIndex = 1
To
25
For
Each
objName
In
ThisWorkbook.Names
If
objName.Name =
"AbwK"
&
CStr
(lngIndex)
Then
Exit
For
Next
If
Not
objName
Is
Nothing
Then
If
Not
IsError(Evaluate(objName.RefersTo))
Then
If
Not
IsEmpty(Range(objName.Name).Value)
Then
Set
objCommandBarButton = objCommandBar.Controls.Add(Type:=msoControlButton)
With
objCommandBarButton
.Caption = Range(objName.Name).Value
.OnAction =
"'Färbe "
""
& Replace$(objName.Name,
"K"
,
"Kk"
) &
""
"'"
End
With
End
If
End
If
End
If
Next
Set
objCommandBarButton =
Nothing
Set
objCommandBar =
Nothing
Set
objName =
Nothing
End
Sub