Live-Forum - Die aktuellen Beiträge
Datum
Titel
28.04.2024 20:05:21
28.04.2024 18:33:31
28.04.2024 18:25:12
28.04.2024 14:18:05
Anzeige
Archiv - Navigation
1932to1936
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
Inhaltsverzeichnis

MsgBox text

MsgBox text
17.06.2023 16:25:24
G.

Ich möchte in meiner MsGBox einen Text "H2O" mit tiefergestellter 2 erstellen.

Mit freundlichem Gruß
G.

30
Beiträge zum Forumthread
Beiträge zu diesem Forumthread

Betreff
Datum
Anwender
Anzeige
AW: MsgBox text
17.06.2023 16:39:55
Oberschlumpf
dann verwende ein Userform, dass du wie eine MsgBox gestaltest. In dem Userform könntest du mehrere Label-Controls "hoch-" bzw "tiefstellen" und die, die du benötigst, mit visible=true zeigen und die anderen mit visible=false ausblenden...und auch in den left-, right-Angaben verschieben, wenn erforderlich

Direkte Verwendung einer MsgBox, so wie du es möchtest, ist nicht möglich


AW: MsgBox text
17.06.2023 16:47:53
RPP63
Moin Oberschlumpf!
Es braucht nicht mehrere Labels.
Die Default-Schriftart Tahoma eines Labels kommt mit der tiefgestellten 2 klar:
Label1.Caption = "H" & ChrW(8322) & "O"
Gruß Ralf


Anzeige
AW: MsgBox text
17.06.2023 17:19:22
Oberschlumpf
Hallo Ralf,

und danke Ralf! :-)
Die Feinheiten unterschiedlicher Schriftarten kenn ich nicht so aus dem Effeff - wieder was (dazu)gelernt!

Mit nur einem Label is das Ganze dann ja ganz einfach umzusetzen, als noch zusätzlich das Managen von vielen Labels wie in meinem Vorschlag.

Ciao
Thorsten


AW: MsgBox text
17.06.2023 16:42:16
RPP63
Moin!
Die tiefgestellte 2 (₂) ist Unicode 8322
Dummerweise verfügt die Systemschriftart der MsgBox nixht über diesen erweiterten Satz.
Folglich schlägt folgendes fehl:
MsgBox "H" & ChrW(8322) & "O"
Man müsste folglich ein Label in einem Userform nehmen, bei dem man die Schriftart einstellen kann.
Ich lasse offen!

Gruß Ralf


Anzeige
AW: MsgBox text
17.06.2023 17:04:12
Pappawinni
Mit MsgBoxW soll das funktionieren, hat mir Google erzählt..
Private Declare PtrSafe Function MessageBoxW Lib "User32" (ByVal hWnd As LongPtr, ByVal lpText As LongPtr, ByVal lpCaption As LongPtr, ByVal uType As Long) As Long

Public Function MsgBoxW(Prompt As String, Optional Buttons As VbMsgBoxStyle = vbOKOnly, Optional Title As String = "Microsoft Excel") As VbMsgBoxResult
    MsgBoxW = MessageBoxW(Application.hWnd, StrPtr(Prompt), StrPtr(Title), Buttons)
End Function
Ungetestet


AW: MsgBox text
17.06.2023 17:18:07
G.
Danke für Euere Antworten. Ähnliche Erfahrungen habe ich auch schon gemacht.
Die Antwort von Pappawinni ist mir zu gryptisch.
Beim Umschreiben für VBA komme ich mehr als ins schleudern. Kannst Du mir dabei helfen?
Danke.


Anzeige
AW: MsgBox text
17.06.2023 17:33:25
Pappawinni
Da ist nichts kryptisch :) und man muss auch nichts verbiegen.
Den Code hab ich mal eben in ein allgemeines Modul gepackt und dann in einem anderen Modul

Sub test()
 MsgBoxW "H" & ChrW(8322) & "O"
End Sub
und das sah aus, als würde es funktionieren.


AW: MsgBox text
17.06.2023 17:41:15
G.
Nein tut es nicht, die 2 bleibt wie sie ist.


AW: MsgBox text
17.06.2023 17:46:41
Oberschlumpf
na ja, dann erstell doch, wie auch vorgeschlagen, ein kleines Userform mit nur 1 Label...und eben ein oder einige Button - oder wieso kannst du kein Userform erstellen?


AW: MsgBox text
17.06.2023 17:58:03
Ulf
Musst natürlich auch die geänderte Funktion aufrufen, oder:

Option Explicit

Private Declare PtrSafe Function MessageBoxW Lib "User32" (ByVal hWnd As LongPtr, ByVal lpText As LongPtr, ByVal lpCaption As LongPtr, ByVal uType As Long) As Long

'Public Function MsgBoxW(Prompt As String, Optional Buttons As VbMsgBoxStyle = vbOKOnly, Optional Title As String = "Microsoft Excel") As VbMsgBoxResult
    'MsgBoxW = MessageBoxW(Application.hWnd, StrPtr(Prompt), StrPtr(Title), Buttons)
'End Function

Public Function MsgBox(Prompt As String, Optional Buttons As VbMsgBoxStyle = vbOKOnly, Optional Title As String = "Microsoft Excel") As VbMsgBoxResult
    MsgBox = MessageBoxW(Application.hWnd, StrPtr(Prompt), StrPtr(Title), Buttons)
End Function
    
Public Sub test()
    MsgBox "H" & ChrW(8322) & "O"
End Sub
überschreiben
hth


Anzeige
AW: MsgBox text
17.06.2023 17:50:20
Oberschlumpf
und das hier...

Userbild

...kommt übrigens raus, wenn man den gezeigten Code so verwendet wie gezeigt - man muss also nix ändern - somit bräuchtest du auch nicht ein Userform


AW: MsgBox text
17.06.2023 17:51:30
Oberschlumpf
hmm???? sehe erst jetzt, du verwendest Excel 2019, ich aber verwende "noch" Excel 2016 - aber ich glaub nich, dass der Code nur wegen der anderen Version bei dir nicht funktioniert


AW: MsgBox text
17.06.2023 20:46:12
Volti
Das ist ja eine Windows-Function, da ist m.E. die Excelversion nicht maßgebend.
Gruß KH


Anzeige
AW: MsgBox text
17.06.2023 17:53:27
Pappawinni
Hast du auch wirklich MsgBoxW verwendet.
Bei mir tut es:
Userbild


AW: MsgBox text
17.06.2023 22:33:21
Pappawinni
passiert das nur mir?
Ich poste ne Lösung von der ich überzeugt bin.
Der TO meldet "funktioniert nicht" und lässt nichts mehr von sich hören...
Da frag ich mich dann schon, ob ich darauf Lust hab.


AW: MsgBox text
21.06.2023 17:18:57
G.
Guten Tag Pappawinni.
Es tut mir leid wenn ich Dich verärgert habe, aber ich war seit dem 18.06.23 ein paar Tage abwesend. Entschuldigung.
Zum Thema. Ich zeige mal meine Anwendung, und komme damit aber nicht zum Ziel.

FehlerT = "H" & ChrW(8322) & "O: Zählerstand ist keine Zahl, oder fehlt"
If MsgBoxW(FehlerT, vbExclamation + vbOKOnly, "Parzelle: " & .Range("A" & CStr(Zeile)) & ", " & _
.Range("E" & CStr(Zeile)) & " Fehler " & FehlerNr) = vbOK Then Exit Sub
Wenn ich MsGBoxW verwende wird ein Fehler gemeldet: Fehler beim Kompilieren: Sub oder Function nicht definiert


Anzeige
AW: MsgBox text
21.06.2023 17:32:49
G.
Noch eine Frage und feststellung: wie oder was mußich eintragen, wenn ich die Office Version 2021 benutze?


AW: MsgBox text
21.06.2023 19:42:27
Pappawinni
Die Funktion MsgBoxW hab ich am Anfang gepostet und wenn du das in ein allgemeines Modul rein kopierst, sollte VBA die Funktion kennen.


AW: MsgBox text
21.06.2023 20:12:01
G.
Ich habe jetzt die vollständige Version und die kurze Version in meinen VBA-Code getestet.
MsgBoxW wird als Syntaxfehler abgewiesen.


AW: MsgBox text
21.06.2023 20:21:25
Pappawinni
Welche kurze Version?


AW: MsgBox text
21.06.2023 20:24:05
Pappawinni
Du brauchst den Code vollständig und nicht nur einen Teil davon und nur MsgBoxW ist Public


AW: MsgBox text
21.06.2023 20:56:37
Daniel
Hi Pappawinni
hast du beachtet, dass hier die Messagebox mit mehreren Buttons und Auswahloption benötigt wird und nicht nur die einfache OK-Box?
Gruß Daniel


Anzeige
AW: MsgBox text
21.06.2023 21:12:24
Pappawinni
Das sollte auch möglich sein, aber solange da noch nicht mal ne einfache MsgBox raus kommt...


AW: MsgBox text
21.06.2023 21:49:28
Pappawinni
also ich hab jetzt mal das

Private Declare PtrSafe Function MessageBoxW Lib "User32" (ByVal hWnd As LongPtr, ByVal lpText As LongPtr, ByVal lpCaption As LongPtr, ByVal uType As Long) As Long

Sub test()
Dim FehlerT As String

FehlerT = "H" & ChrW(8322) & "O: Zählerstand ist keine Zahl, oder fehlt"
If MsgBoxW(FehlerT, vbExclamation + vbOKOnly, "blabla") = vbOK Then Exit Sub
MsgBox "fertig"

End Sub

                  
Public Function MsgBoxW(Prompt As String, Optional Buttons As VbMsgBoxStyle = vbOKOnly, Optional Title As String = "Microsoft Excel") As VbMsgBoxResult
    MsgBoxW = MessageBoxW(Application.hWnd, StrPtr(Prompt), StrPtr(Title), Buttons)
End Function
In ein Modul rein gesetzt, und das funktioniert.
Ich weiss natürlich nicht, was da für bei dem TO in dem Titel (wo ich "blabla" stehen habe) alles zusammen gebastelt wird und bin eigentlich auch davon ausgegangen, dass die Funktionsdeklaration für MsgBoxW in einem eigenen Modul steht, so wie ich es beschreiben hatte.....
Ist auch nur eine "einfache" Messagebox mit OK, halt mit dem Icon "Ausrufezeichen"


Anzeige
AW: MsgBox text
21.06.2023 21:32:39
volti
Hallo,

ich greife jetzt mal Deinen geposteten Code hier auf....
Neben einigen anderen Fehlern gibt es folgende Besonderheit bzgl. der MessageBoxW.
Im Gegensatz zur MessageBoxA (auch Excel-MsgBox) werden hier die Texte nicht als String übergeben, sondern als Longpointer. Das ist ein Zeiger auf eine Variable oder eine ganze Struktur im Arbeitsspeicher.
Du kannst hier also nicht direkt Text oder Zellreferenzen übergeben, sondern musst diese erst in eine Variable schaffen und mit StrPtr() übergeben oder auch direkt mit StrPtr() übergeben.
Die wirkliche Funktion aus der API heißt MessageBoxW. Du kannst ihr aber auch einen eigenen Name verpassen. Das habe ich im unteren Codebeispiel einfach mal gemacht.
Die Declare muss nicht Public sein, kann auch Private sein und darf auch in einem Arbeitsblattmodul liegen.

Hier das Codebeispiel:
Passe es dann noch auf Deine Bedürfnisse an.

Code:


Private Declare PtrSafe Function MeineMsgBox Lib "User32" Alias "MessageBoxW" ( _ ByVal hWnd As LongPtr, ByVal lpText As LongPtr, _ ByVal lpCaption As LongPtr, ByVal uType As Long) As Long Sub Test() Dim FehlerHT As String, Zeile As Long, FehlerNr Zeile = 1 FehlerT = "H" & ChrW(8322) & "O: Zählerstand ist keine Zahl, oder fehlt" If MeineMsgBox(Application.hWnd, StrPtr(FehlerT), StrPtr("Parzelle: " _ & Range("A" & Zeile) & ", " & Range("E" & Zeile) _ & " Fehler " & FehlerNr), vbExclamation + vbOKCancel) = vbOK Then Exit Sub End Sub

_________________________
viele Grüße aus Freigericht 😊
Karl-Heinz



Anzeige
AW: MsgBox text
21.06.2023 21:20:00
GerdL
Moin,

am Titel musst du noch feilen. Hoffe du hast kein 64er Bit.
Option Explicit



Private Declare PtrSafe Function MessageBoxW Lib "User32" (ByVal hWnd As LongPtr, ByVal lpText As LongPtr, ByVal lpCaption As LongPtr, ByVal uType As Long) As Long


Public Function MsgBox(Prompt As String, Optional Buttons As VbMsgBoxStyle = vbOKOnly, Optional Title As String = "Microsoft Excel") As VbMsgBoxResult
    MsgBox = MessageBoxW(Application.hWnd, StrPtr(Prompt), StrPtr(Title), Buttons)
End Function
    
Public Sub test()

    Dim FehlerT As String, Titel As String
    
    Titel = "Parzelle: " & "4711" & ", " _
            & "/123" & " Fehler " & "0815"
    FehlerT = "H" & ChrW(8322) & "O: Zählerstand ist keine Zahl, oder fehlt"
    
    If MsgBox(FehlerT, vbExclamation + vbOKCancel, Titel) = vbCancel Then Exit Sub
    
    MsgBox "mach was"
    
End Sub
Gruß Gerd


AW: MsgBox text
21.06.2023 21:45:17
Volti
Hallo Gerd,
Die Funktion ist so wie sie deklariert ist 64 Bit tauglich.
Gruß KH


AW: MsgBox text
21.06.2023 21:57:16
Ulf
Weil des Pappas Idee gut und allgemeingültig, wird sie selbst verwendet

Option Explicit

Public Enum enMsgBox
    MB_ABORTRETRYIGNORE = &H2
    '   The message box contains three push buttons: Abort, Retry, and Ignore.
    MB_CANCELTRYCONTINUE = &H6
    '   The message box contains three push buttons: Cancel, Try Again, Continue. Use this message box type instead of MB_ABORTRETRYIGNORE.
    MB_HELP = &H4000
    '   Adds a Help button to the message box. When the user clicks the Help button or presses F1, the system sends a WM_HELP message to the owner.
    MB_OK = &H0
    '   The message box contains one push button: OK. This is the default.
    MB_OKCANCEL = &H1
    '   The message box contains two push buttons: OK and Cancel.
    MB_RETRYCANCEL = &H5
    '   The message box contains two push buttons: Retry and Cancel.
    MB_YESNO = &H4
    '   The message box contains two push buttons: Yes and No.
    MB_YESNOCANCEL = &H3
    '   The message box contains three push buttons: Yes, No, and Cancel.
    '   To display an icon in the message box, specify one of the following values.
    MB_ICONEXCLAMATION = &H30
    '   An exclamation-point icon appears in the message box.
    MB_ICONWARNING = &H30
    '   An exclamation-point icon appears in the message box.
    MB_ICONINFORMATION = &H40
    '   An icon consisting of a lowercase letter i in a circle appears in the message box.
    MB_ICONASTERISK = &H40
    '   An icon consisting of a lowercase letter i in a circle appears in the message box.
    MB_ICONQUESTION = &H20
    '   A question-mark icon appears in the message box. The question-mark message icon is no longer recommended because it does not clearly represent a specific type of message and because the phrasing of a message as a question could apply to any message type. In addition, users can confuse the message symbol question mark with Help information. Therefore, do not use this question mark message symbol in your message boxes. The system continues to support its inclusion only for backward compatibility.
    MB_ICONSTOP = &H10
    '   A stop-sign icon appears in the message box.
    MB_ICONERROR = &H10
    '   A stop-sign icon appears in the message box.
    MB_ICONHAND = &H10
    '   A stop-sign icon appears in the message box.
    '   To indicate the default button, specify one of the following values.
    MB_DEFBUTTON1 = &H0
    '   The first button is the default button.
    '   MB_DEFBUTTON1 is the default unless MB_DEFBUTTON2, MB_DEFBUTTON3, or MB_DEFBUTTON4 is specified.
    MB_DEFBUTTON2 = &H100
    '   The second button is the default button.
    MB_DEFBUTTON3 = &H200
    '   The third button is the default button.
    MB_DEFBUTTON4 = &H300
    '   The fourth button is the default button.
    '   To indicate the modality of the dialog box, specify one of the following values.
    MB_APPLMODAL = &H0
    '   The user must respond to the message box before continuing work in the window identified by the hWnd parameter. However, the user can move to the windows of other threads and work in those windows.
    '   Depending on the hierarchy of windows in the application, the user may be able to move to other windows within the thread. All child windows of the parent of the message box are automatically disabled, but pop-up windows are not.
    '   MB_APPLMODAL is the default if neither MB_SYSTEMMODAL nor MB_TASKMODAL is specified.
    MB_SYSTEMMODAL = &H1000
    '   Same as MB_APPLMODAL except that the message box has the WS_EX_TOPMOST style. Use system-modal message boxes to notify the user of serious, potentially damaging errors that require immediate attention (for example, running out of memory. This flag has no effect on the user's ability to interact with windows other than those associated with hWnd.
    MB_TASKMODAL = &H2000
    '   Same as MB_APPLMODAL except that all the top-level windows belonging to the current thread are disabled if the hWnd parameter is NULL. Use this flag when the calling application or library does not have a window handle available but still needs to prevent input to other windows in the calling thread without suspending other threads.
    '   To specify other options, use one or more of the following values.
    MB_DEFAULT_DESKTOP_ONLY = &H20000
    '   Same as desktop of the interactive window station. For more information, see Window Stations.
    '   If the current input desktop is not the default desktop, MessageBox does not return until the user switches to the default desktop.
    MB_RIGHT = &H80000
    '   The text is right-justified.
    MB_RTLREADING = &H100000
    '   Displays message and caption text using right-to-left reading order on Hebrew and Arabic systems.
    MB_SETFOREGROUND = &H10000
        'The message box becomes the foreground window. Internally, the system calls the SetForegroundWindow function for the message box.
    MB_TOPMOST = &H40000
        'The message box is created with the WS_EX_TOPMOST window style.
    MB_SERVICE_NOTIFICATION = &H200000
        'The caller is a service notifying the user of an event. The function displays a message box on the current active desktop, even if there is no user logged on to the computer.
        'Terminal Services: If the calling thread has an impersonation token, the function directs the message box to the session specified in the impersonation token.
        'If this flag is set, the hWnd parameter must be NULL. This is so that the message box can appear on a desktop other than the desktop corresponding to the hWnd.
        'For information on security considerations in regard to using this flag, see Interactive Services. In particular, be aware that this flag can produce interactive content on a locked desktop and should therefore be used for only a very limited set of scenarios, such as resource exhaustion.
End Enum


Private Declare PtrSafe Function MessageBoxW Lib "User32" (ByVal hWnd As LongPtr, ByVal lpText As LongPtr, ByVal lpCaption As LongPtr, ByVal uType As Long) As Long

Public Function MsgBox(Prompt As String, Optional Buttons As enMsgBox = enMsgBox.MB_DEFBUTTON1 + enMsgBox.MB_OKCANCEL + enMsgBox.MB_ICONWARNING, Optional Title As String = "Microsoft Excel") As VbMsgBoxResult
    MsgBox = MessageBoxW(Application.hWnd, StrPtr(Prompt), StrPtr(Title), Buttons)
End Function
    
Public Sub test()
    MsgBox "H" & ChrW(8322) & "O"
End Sub
hth
Ulf


AW: MsgBox text
22.06.2023 11:40:09
G.
Guten Tag.
Vorab möchte ich allen Mitwirkenden meinen Dank sagen.
Respekt wie intensiv sich zu diesem Problem beschäftigt wurde (auch zu welchen Urzeiten).
Die Mühe hat sich das gelohnt. Es funktioniert jetzt und ich habe wieder dazugelernt.
Nochmals Danke!


AW: MsgBox text
22.06.2023 13:25:20
Pappawinni
Na Gott sei Dank. Das war ja eine schwere Geburt...

Links zu Excel-Dialogen

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige