Live-Forum - Die aktuellen Beiträge
Anzeige
Archiv - Navigation
960to964
Aktuelles Verzeichnis
Verzeichnis Index
Übersicht Verzeichnisse
Vorheriger Thread
Rückwärts Blättern
Nächster Thread
Vorwärts blättern
Anzeige
HERBERS
Excel-Forum (Archiv)
20+ Jahre Excel-Kompetenz: Von Anwendern, für Anwender
960to964
960to964
Aktuelles Verzeichnis
Verzeichnis Index
Verzeichnis Index
Übersicht Verzeichnisse
Inhaltsverzeichnis

MsgBox

MsgBox
22.03.2008 19:27:00
Peter
Hallo VBA-Experten.
Ich benötige mal Eure Hilfe.
Wie kann ich eine MessageBox mit den zwei Buttons "Bearbeiten" und "Abbrechen" hinbekommen.
Danke schon mal
Peter

15
Beiträge zum Forumthread
Beiträge zu diesem Forumthread

Betreff
Datum
Anwender
Anzeige
AW: MsgBox
22.03.2008 19:31:00
Jens
Hallo Peter
Die Buttons einer MsgBox sind fest, d.h. die kannst Du nicht ändern.
Bleibt Dir aber die Möglichkeit, selber eine Userform nach Deinen Vorstellungen zu erstellen.
Gruß aus dem Sauerland
Jens

AW: MsgBox
22.03.2008 19:36:00
Peter
Hallo Jens.
Vielleicht bleibt mir nichts anderes übrig.
Ich hatte allerdings gehofft, das es eine voreingestellte Möglichkeit gibt.
Die Buttons Ja/Nein , ok, aber auch Abbrechen/Wiederholen/Ignorieren gibt es ja auch.
Meine Hoffnung war, dass ich nur die richtige Synthax nicht gefunden habe.
Trotzdem Danke
Peter

AW: MsgBox
22.03.2008 19:42:06
René
Hi Peter
Ich würde es so "lösen", nicht ganz was du willst, aber halbwegs denk ich.

Sub Boxauswahl()
Dim m As Integer
m = MsgBox("Wollen Sie bearbeiten oder abbrechen?", vbOKCancel, "Bearbeitung oder Abbruch")
If m = 1 Then
MsgBox "Bearbeitung gewählt."
Else
MsgBox "Abbruch gewählt"
End If
End Sub


Gruß René

Anzeige
AW: MsgBox
22.03.2008 19:49:16
Peter
Hi René
Danke für Deine Antwort.
Allerdings sollen mit der fertigen Anwendung auch meine Kollegen arbeiten und da möchte ich schon eine
eindeutige Bezeichnung.
Ich werde wohl doch eine eigene UserForm dafür anlegen.
gruß
Peter

AW: MsgBox
22.03.2008 20:40:41
Nepumuk
Hi,
geht doch:
' **********************************************************************
' Modul: Modul2 Typ: Allgemeines Modul
' **********************************************************************

Option Explicit

Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" ( _
    ByVal lpClassName As String, _
    ByVal lpWindowName As String) As Long
Private Declare Function SetTimer Lib "user32.dll" ( _
    ByVal hWnd As Long, _
    ByVal nIDEvent As Long, _
    ByVal uElapse As Long, _
    ByVal lpTimer As Long) As Long
Private Declare Function KillTimer Lib "user32.dll" ( _
    ByVal hWnd As Long, _
    ByVal nIDEvent As Long) As Long
Private Declare Function MessageBox Lib "user32.dll" _
    Alias "MessageBoxA" ( _
    ByVal hWnd As Long, _
    ByVal lpText As String, _
    ByVal lpCaption As String, _
    ByVal wType As Long) As Long
Private Declare Function SendDlgItemMessage Lib "user32.dll" _
    Alias "SendDlgItemMessageA" ( _
    ByVal hDlg As Long, _
    ByVal nIDDlgItem As Long, _
    ByVal wMsg As Long, _
    ByVal wParam As Long, _
    ByVal lParam As String) As Long

Private Const WM_SETTEXT = &HC
Private Const GC_CLASSNAMEMSEXCEL = "XLMAIN"
Private Const GC_CLASSNAMEMSDIALOG = "#32770"

Private Enum MsgBoxPlusIcon
    Critical = 16
    Question = 32
    Exclamation = 48
    Information = 64
End Enum

Private strCaption1 As String
Private strCaption2 As String
Private strCaption3 As String
Private strCaption As String

Private hWnd As Long

Private Function MsgBoxPlus(ByVal hWnd As Long, _
        ByVal strText As String, _
        ByVal strTitle As String, _
        ByVal strButton1 As String, _
        Optional ByVal strButton2 As String, _
        Optional ByVal strButton3 As String, _
        Optional ByVal enmSymbol As MsgBoxPlusIcon) As Long

    
    Dim nResult As Long
    
    strCaption1 = strButton1
    strCaption2 = strButton2
    strCaption3 = strButton3
    strCaption = strTitle
    
    nResult = SetTimer(hWnd, 0, 25, AddressOf MsgBoxPlus_TimerEvent)
    
    If strButton2 = "" And strButton3 = "" Then
        nResult = MessageBox(hWnd, strText, strCaption, enmSymbol Or vbOKOnly)
    ElseIf strButton2 <> "" And strButton3 = "" Then
        nResult = MessageBox(hWnd, strText, strCaption, enmSymbol Or vbYesNo)
    Else
        nResult = MessageBox(hWnd, strText, strCaption, enmSymbol Or vbAbortRetryIgnore)
    End If
    
    Select Case nResult
        Case 1, 3, 6
            MsgBoxPlus = 1
        Case 4, 7
            MsgBoxPlus = 2
        Case Else
            MsgBoxPlus = 3
    End Select
    
End Function

Private Sub MsgBoxPlus_TimerEvent()
    
    Dim lngBoxHandle As Long
    
    KillTimer hWnd, 0
    
    lngBoxHandle = FindWindow(GC_CLASSNAMEMSDIALOG, strCaption)
    
    If strCaption2 = "" And strCaption3 = "" Then
        SendDlgItemMessage lngBoxHandle, vbCancel, WM_SETTEXT, 0, strCaption1
    ElseIf strCaption2 <> "" And strCaption3 = "" Then
        SendDlgItemMessage lngBoxHandle, vbYes, WM_SETTEXT, 0, strCaption1
        SendDlgItemMessage lngBoxHandle, vbNo, WM_SETTEXT, 0, strCaption2
    Else
        SendDlgItemMessage lngBoxHandle, vbAbort, WM_SETTEXT, 0, strCaption1
        SendDlgItemMessage lngBoxHandle, vbRetry, WM_SETTEXT, 0, strCaption2
        SendDlgItemMessage lngBoxHandle, vbIgnore, WM_SETTEXT, 0, strCaption3
    End If
    
End Sub

Public Sub Test()
    
    Dim lngButton As Long
    
    hWnd = FindWindow(GC_CLASSNAMEMSEXCEL, Application.Caption)
    
    lngButton = MsgBoxPlus(hWnd, "MsgBox mit oam Gnopf", _
        "Des schded om drin", "Druck mi", , , MsgBoxPlusIcon.Exclamation)
    MsgBox lngButton
    
    lngButton = MsgBoxPlus(hWnd, "MsgBox mit zwoa Gnepf", _
        "Des schded om drin", "so ned", "doch a so", , _
        MsgBoxPlusIcon.Question)
    MsgBox lngButton
    
    lngButton = MsgBoxPlus(hWnd, "MsgBox mit drei Gnepf", _
        "Des schded om drin", "Ko sei", "Mir wuschd", "Leck mi", _
        MsgBoxPlusIcon.Information)
    MsgBox lngButton
    
End Sub

Gruß
Nepumuk

Anzeige
AW: MsgBox
22.03.2008 21:09:27
Peter
Hallo Nepomuk.
Mir ist auf die schnelle nicht alles klar.
Werde es aber morgen mal ausprobieren.
Danke und frohe Ostern
Peter

@Nepumuk
22.03.2008 22:35:54
Jens
Ok, Ok.
Dann lass ich mal die Götter sprechen ;-)
Gut, soweit steck ich denn doch nit in der Materie drin :-)
Aber trotzdem danke dafür. Wieder was gelernt.
Frohes Osterfest noch.
Gruß aus dem Sauerland
Jens

AW: MsgBox
23.03.2008 20:37:00
Peter
Hallo Nepumuk.
Wollte das ganze mal laufen lassen.
Bei mir kommt aber nur eine Fehlermeldung "Unzulässige Verwendung des AddressOf-Operators"
Muss ich da noch einen Verweis aktivieren oder was soll ich umstellen?
Vielleicht kannst du mir da noch helfen.
Gruß
Peter

Anzeige
AW: MsgBox
23.03.2008 20:39:00
Nepumuk
Hallo Peter,
kann ich nicht nachvollziehen. Hast du einen Prozedurnamen geändert oder sowas in der Art?
Gruß
Nepumuk

AW: MsgBox
23.03.2008 21:31:56
Herbert
Hi,
schönes Beispiel dafür, dass nicht alles, was möglich ist, auch gemacht werden sollte.
mfg Herbert

AW: MsgBox
23.03.2008 21:34:00
Peter
Hi Nepumuk.
Nein.
Hab einfach nur das Makro gestartet.
Übrigens, wenn ich bei der Fehlermeldung auf Hilfe gehe, kommt bei mir auch nichts.
Heißt das Hilfe-Fenster öffnet sich, es steht aber nichts drin.
Gruß
Peter

AW: MsgBox
23.03.2008 21:54:32
Nepumuk
Hallo Peter,
aber Excel 2000 stimmt?
Gruß
Nepumuk

Anzeige
AW: MsgBox
23.03.2008 22:07:00
Peter
Hallo Nepumuk.
Leider nicht ganz.
laufen soll das ganze unter Excel 2000. Deshalb auch die Angabe.
Ich selbst habe Excel 2002.
Ich habe gehofft, dass es dann auch unter 2002 laufen müsste.
Gruß
Peter

AW: MsgBox
24.03.2008 11:42:00
Nepumuk
Hallo Peter,
ich lad mal eine funktionierende Mappe hoch. Das ganze sollte ab Excel2000 aufwärts funktionieren.
https://www.herber.de/bbs/user/50967.xls
Gruß
Nepumuk

AW: MsgBox
24.03.2008 14:39:09
Peter
Hallo Nepumuk.
Es funktioniert wunderbar.
Danke
Peter

Links zu Excel-Dialogen

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige