Hallo Rod,
hier der derzeitige Code. Der hatte mal funktioniert. Ist aber VBA.....
Gruß
Karl-Heinz
hier der derzeitige Code. Der hatte mal funktioniert. Ist aber VBA.....
Visual Basic-Quellcode
- Option Explicit
- Private Declare PtrSafe Function GetProcAddress Lib "kernel32" ( _
- ByVal hModule As LongPtr, ByVal lpProcName As String) As LongPtr
- Private Declare PtrSafe Function LoadLibraryA Lib "kernel32" ( _
- ByVal lpLibFileName As String) As LongPtr
- Private Declare PtrSafe Function FreeLibrary Lib "kernel32" ( _
- ByVal hLibModule As LongPtr) As Long
- Private Type MSGBOXPARAMS
- cbSize As Long
- hWndOwner As LongPtr
- hInstance As LongPtr
- lpszText As LongPtr
- lpszCaption As LongPtr
- dwStyle As Long
- lpszIcon As LongPtr
- dwContextHelpId As Long
- lpfnMsgBoxCallback As LongPtr
- dwLanguageId As Long
- End Type
- Private Type MSGBOXDATA
- PARAMS As MSGBOXPARAMS
- pwndOwner As LongPtr ' Nur intern
- dwPadding As Long
- wLanguageId As Long
- pidButton As LongPtr ' Array (Button-IDs)
- ppszButtonText As LongPtr ' Array (Buttontext)
- cButtons As Long ' Anzahl der Buttons
- defButton As Long ' Button-ID Default
- cancelId As Long ' Button-ID Abbruch
- Timeout As Long ' Timeout
- phwndList As LongPtr ' Nur intern
- dwReserved(19) As Long ' Reserviert
- End Type
- Private Declare PtrSafe Function SoftModalMessageBox Lib "user32" (pMsgBoxParams As MSGBOXDATA) As Long
- Function MsgboxEx(ByVal sText As String, _
- Optional ByVal sBtns As String = "OK", _
- Optional ByVal sCaption As String = "Microsoft Excel", _
- Optional ByVal iIcon As Long, _
- Optional ByVal iTimeOut As Long, _
- Optional ByVal iDefBtn As Long) As String
- Dim md As MSGBOXDATA
- Dim lArrBtn() As Long, sArrTxt() As String, i As Long
- Dim hModul As LongPtr, hRet As LongPtr
- hModul = LoadLibraryA("User32.dll") ' Bibliothek laden
- If hModul <> 0& Then
- hRet = GetProcAddress(hModul, "SoftModalMessageBox") ' Funktion vorhanden?
- FreeLibrary hModul ' Bibliothek schließen
- End If
- If hRet = 0 Then Exit Function ' Anzeige nicht möglich
- sArrTxt = Split(sBtns, ",") ' Buttontexte in Array
- ReDim lArrBtn(UBound(sArrTxt)) ' ID-Array dimensionieren
- For i = 0 To UBound(lArrBtn): lArrBtn(i) = i + 1: Next i ' IDs in Array setzen
- With md
- With .PARAMS
- .cbSize = LenB(md.PARAMS)
- .hWndOwner = Application.hwnd ' Excel-Handle
- .hInstance = Application.HinstancePtr ' Excel-Instance
- .lpszText = StrPtr(sText) ' Messagetext
- .lpszCaption = StrPtr(sCaption) ' Titel
- .dwStyle = iIcon ' Icon setzen
- End With
- .cancelId = 1
- .cButtons = UBound(lArrBtn) + 1 ' Anzahl der Buttons
- If iDefBtn = 0 Or iDefBtn > .cButtons Then iDefBtn = 1
- .defButton = (iDefBtn - 1) ' DefaultButtonID
- .pidButton = VarPtr(lArrBtn(0)) ' IDs übergeben
- .ppszButtonText = VarPtr(sArrTxt(0)) ' Buttontexte übergeben
- .Timeout = (iTimeOut - 1) ' Timeout setzen, 0=abgeschaltet
- End With
- i = SoftModalMessageBox(md) ' MsgBox anzeigen
- If i = 32000 Then
- MsgboxEx = "Timeout"
- Else
- MsgboxEx = sArrTxt(i - 1) ' Ergebnistext zurückgeben
- End If
- End Function
- Sub Test()
- MsgBox MsgboxEx("Bitte wähle eine Option aus!", "Option 1,Option 2,Option 3,Option 4,Option 5,Option 6", "Meine Auswahl", vbExclamation, 0, 1)
- End Sub
Gruß
Karl-Heinz