Thema Datum  Von Nutzer Rating
Antwort
13.01.2017 19:15:50 Kakuda89
NotSolved
13.01.2017 21:42:24 Gast4485
NotSolved
13.01.2017 21:46:38 Kakuda89
NotSolved
13.01.2017 21:56:12 Gast4138
NotSolved
Rot Command Button nach einfügen programmieren
14.01.2017 08:31:33 Gast84056
NotSolved
14.01.2017 09:26:58 Gast89896
NotSolved
14.01.2017 12:10:53 Kakuda89
NotSolved
14.01.2017 13:08:11 Kakuda89
Solved

Ansicht des Beitrags:
Von:
Gast84056
Datum:
14.01.2017 08:31:33
Views:
808
Rating: Antwort:
  Ja
Thema:
Command Button nach einfügen programmieren

Die alten FormControls haben ein/zwei Vorteile gegenüber ihren ActiveX Kollegen (welche du in deinem Code ansprichst).

Eins davon ist, dass man ihnen ein Makro zuweisen kann - siehe ein Beispiel dazu:

'Module
Option Explicit

Sub Example()
  
  Dim shp As Shape
  
  With ActiveSheet.Shapes
    
    Set shp = .AddFormControl(XlFormControl.xlButtonControl, 10, 10, 150, 80)
    shp.Name = "MyButton1"
    shp.OLEFormat.Object.Caption = shp.Name
    shp.OnAction = "OnBtnClick"
    
    Set shp = .AddFormControl(XlFormControl.xlButtonControl, shp.Left, shp.Top + shp.Height + 5, 150, 80)
    shp.Name = "MyButton2"
    shp.OLEFormat.Object.Caption = shp.Name
    shp.OnAction = "OnBtnClick"
    
    Set shp = .AddFormControl(XlFormControl.xlButtonControl, shp.Left, shp.Top + shp.Height + 5, 150, 80)
    shp.Name = "TheBlackSheep"
    shp.OLEFormat.Object.Caption = shp.Name
    shp.OnAction = "OnBtnClick"
    
    Set shp = .AddFormControl(XlFormControl.xlButtonControl, shp.Left, shp.Top + shp.Height + 5, 150, 80)
    shp.Name = "MyButton3"
    shp.OLEFormat.Object.Caption = shp.Name
    shp.OnAction = "OnBtnClick"
    
  End With
  
End Sub


Public Sub OnBtnClick()
  
  If 0 <> StrComp(TypeName(Application.Caller), "String", vbTextCompare) Then
    Exit Sub
  End If
  
  Dim shp As Excel.Shape
  
  Set shp = ActiveSheet.Shapes(Application.Caller)
  If shp.Type <> MsoShapeType.msoFormControl Then Exit Sub
  If shp.FormControlType <> XlFormControl.xlButtonControl Then Exit Sub
  
  Select Case shp.Name
    Case "MyButton1", "MyButton2"
      Call MsgBox(shp.Name & ": Muuuh!", vbInformation)
    Case "MyButton3"
      Call MsgBox(shp.Name & ": Määäääääh!", vbInformation)
    Case Else
      Call MsgBox("UNHANDLED CALL" & vbNewLine & _
                    "Button: '" & shp.Name & "'" & vbNewLine & _
                    "Routine: 'OnBtnClick'", _
                    vbExclamation)
      Exit Sub
  End Select
  
End Sub

Gruß


Ihre Antwort
  • Bitte beschreiben Sie Ihr Problem möglichst ausführlich. (Wichtige Info z.B.: Office Version, Betriebssystem, Wo genau kommen Sie nicht weiter)
  • Bitte helfen Sie ebenfalls wenn Ihnen geholfen werden konnte und markieren Sie Ihre Anfrage als erledigt (Klick auf Häckchen)
  • Bei Crossposting, entsprechende Links auf andere Forenbeiträge beifügen / nachtragen
  • Codeschnipsel am besten über den Code-Button im Text-Editor einfügen
  • Die Angabe der Emailadresse ist freiwillig und wird nur verwendet, um Sie bei Antworten auf Ihren Beitrag zu benachrichtigen
Thema: Name: Email:



  • Bitte beschreiben Sie Ihr Problem möglichst ausführlich. (Wichtige Info z.B.: Office Version, Betriebssystem, Wo genau kommen Sie nicht weiter)
  • Bitte helfen Sie ebenfalls wenn Ihnen geholfen werden konnte und markieren Sie Ihre Anfrage als erledigt (Klick auf Häckchen)
  • Bei Crossposting, entsprechende Links auf andere Forenbeiträge beifügen / nachtragen
  • Codeschnipsel am besten über den Code-Button im Text-Editor einfügen
  • Die Angabe der Emailadresse ist freiwillig und wird nur verwendet, um Sie bei Antworten auf Ihren Beitrag zu benachrichtigen

Thema Datum  Von Nutzer Rating
Antwort
13.01.2017 19:15:50 Kakuda89
NotSolved
13.01.2017 21:42:24 Gast4485
NotSolved
13.01.2017 21:46:38 Kakuda89
NotSolved
13.01.2017 21:56:12 Gast4138
NotSolved
Rot Command Button nach einfügen programmieren
14.01.2017 08:31:33 Gast84056
NotSolved
14.01.2017 09:26:58 Gast89896
NotSolved
14.01.2017 12:10:53 Kakuda89
NotSolved
14.01.2017 13:08:11 Kakuda89
Solved