AW: Konstante und Menubezeichnung ändern
20.02.2010 08:56:54
Nepumuk
Hallo,
natürlich kannst du die Caption des Menüs und des Buttons ändern. Aber ein Zellwert ist und kann keine Konstante sein. Konstante besagt ja schon, dass deren Wert zur Laufzeit nicht änderbar ist. Der Inhalt einer Zelle ist aber zu jeder Zeit änderbar.
' **********************************************************************
' Modul: Tabelle1 Typ: Element der Mappe(Sheet, Workbook, ...)
' **********************************************************************
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 1 And Target.Row < 3 Then Call Set_Caption
End Sub
' **********************************************************************
' Modul: Modul1 Typ: Allgemeines Modul
' **********************************************************************
Option Explicit
Const TAG_POPUP = "Peter"
Const CAPTION_POPUP = "&Test"
Const CAPTION_BUTTON = "&Import"
Public Sub Create_Menue()
Dim objPopup As CommandBarPopup, objButton As CommandBarButton
Dim intIndex As Integer
Call Delete_Menue
For intIndex = 1 To 2
Set objPopup = CommandBars(intIndex).Controls.Add( _
Type:=msoControlPopup, Temporary:=True)
objPopup.Tag = TAG_POPUP
Set objButton = objPopup.Controls.Add(Type:=msoControlButton)
objButton.OnAction = "Machwas1"
Next
Call Set_Caption
Set objPopup = Nothing
Set objButton = Nothing
End Sub
Public Sub Delete_Menue()
Dim objControls As CommandBarControls, objControl As CommandBarControl
Set objControls = CommandBars.FindControls(Tag:=TAG_POPUP)
If Not objControls Is Nothing Then
For Each objControl In objControls
objControl.Delete
Next
Set objControls = Nothing
Set objControl = Nothing
End If
End Sub
Public Sub Set_Caption()
Dim objControls As CommandBarControls, objControl As CommandBarControl
Dim strPopupCaption As String, strButtonCaption As String
If Not IsEmpty(Tabelle1.Cells(1, 1).Value) Then
strPopupCaption = Tabelle1.Cells(1, 1).Value
Else
strPopupCaption = CAPTION_POPUP
End If
If Not IsEmpty(Tabelle1.Cells(2, 1).Value) Then
strButtonCaption = Tabelle1.Cells(2, 1).Value
Else
strButtonCaption = CAPTION_BUTTON
End If
Set objControls = CommandBars.FindControls(Tag:=TAG_POPUP)
If Not objControls Is Nothing Then
For Each objControl In objControls
objControl.Caption = strPopupCaption
objControl.Controls(1).Caption = strButtonCaption
Next
Set objControls = Nothing
Set objControl = Nothing
End If
End Sub
Public Sub Machwas1()
' MsgBox "Daten werden importiert", vbExclamation
Call DatenEintragen
'Application.StatusBar = ""
End Sub
Gruß
Nepumuk