Live-Forum - Die aktuellen Beiträge
Datum
Titel
24.04.2024 19:29:30
24.04.2024 18:49:56
Anzeige
Archiv - Navigation
280to284
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
280to284
280to284
Aktuelles Verzeichnis
Verzeichnis Index
Verzeichnis Index
Übersicht Verzeichnisse
Inhaltsverzeichnis

Position einer MsgBox ändern

Position einer MsgBox ändern
12.07.2003 11:20:04
Lothar Ehret
Wie kann ich bei einer MsgBox die Anzeige-Position bestimmen? Top/Left scheint bei einer MsgBox nicht zu funktionieren.
Vielen Dank im voraus für jede Hilfe!
Lothar

6
Beiträge zum Forumthread
Beiträge zu diesem Forumthread

Betreff
Datum
Anwender
Anzeige
AW: Position einer MsgBox ändern
12.07.2003 12:09:54
Knut
Das geht nur sehr aufwändig über API- Functions.
Bastel dir doch ein userform, das ist flexibler.
Knut

AW: Position einer MsgBox ändern
12.07.2003 14:51:56
Lothar Ehret
Hallo Knut,
danke für die Antwort. Die Idee hatte ich auch schon, es wäre mit einer MsgBox nur insofern einfacher, als daß ich diese unproblematisch innerhalb einer FOR-NETX -Schleife in einem Makro aufrufen kann, welches bereits aus einer Userform heraus aufgerufen wird. Mit der MsgBox soll eigentlich nur abgefragt werden, ob die Schleife (eine Suchroutine innerhalb eines Tabellenbereiches) beendet werden soll. Wenn ich innerhalb dieser Schleife eine weitere Userform aufrufe, muß ich irgendwie von diesem Makro in ein anderes verzweigen (neue Userform) und aus dieser wieder in das alte Makro zurückkehren. Dieses habe ich im Moment noch nicht auf die Reihe gebracht.
Gruß
Lothar

Anzeige
AW: Position einer MsgBox ändern
12.07.2003 23:45:15
NE
Hallo,
versuch' mal folgendes, allerdings weiss ich nicht ob's unter vba läuft,
Code von Detlev Schubert, gefunden unter: www.vb-fun.de
hope it helps
Gruss Nancy
--
'-------------------------- module1.bas -------------------------
Option Explicit
Public Declare Function SetWindowPos Lib "user32" _
(ByVal hwnd As Long, ByVal hWndInsertAfter As Long, _
ByVal x As Long, ByVal y As Long, ByVal cx As Long, _
ByVal cy As Long, ByVal wFlags As Long) As Long
Public Declare Function SetWindowsHookEx Lib "user32" Alias _
"SetWindowsHookExA" (ByVal idHook As Long, ByVal lpfn As Long, _
ByVal hmod As Long, ByVal dwThreadId As Long) As Long
Public Declare Function UnhookWindowsHookEx Lib "user32" _
(ByVal hHook As Long) As Long
Public Declare Function GetCurrentThreadId Lib "kernel32" () As Long
Public Const SWP_NOSIZE = &H1
Public Const SWP_NOZORDER = &H4
Public Const SWP_NOACTIVATE = &H10
Public Const HCBT_ACTIVATE = 5
Public Const WH_CBT = 5
Public hHook As Long
Public posX As Long
Public posY As Long
Public Function WinProc(ByVal lMsg As Long, ByVal wParam As Long, _
ByVal lParam As Long) As Long
If lMsg = HCBT_ACTIVATE Then
SetWindowPos wParam, 0, posX, posY, 0, 0, SWP_NOSIZE Or _
SWP_NOZORDER Or SWP_NOACTIVATE
UnhookWindowsHookEx hHook
End If
WinProc = False
End Function

'------------------------- form1.frm ---------------------------
Option Explicit


Private Sub Form_Load()
txtPosX = 0
txtPosY = 0
End Sub


Private Sub Command1_Click()
Dim hInst As Long, Thread As Long
Dim msg As String
If Check1.Value = 1 Then
msg$ = "Die MessageBox ist jetzt zentriert."
Else
hInst = App.hInstance
Thread = GetCurrentThreadId()
hHook = SetWindowsHookEx(WH_CBT, AddressOf WinProc, _
hInst, Thread)
posX = CLng(txtPosX)
posY = CLng(txtPosY)
msg$ = "Die Position der MessageBox ist an:" & _
vbCrLf & vbCrLf & "X-Position: " & posX & vbCrLf & _
"Y-Position: " & posY
End If
MsgBox msg$, vbOKOnly + vbInformation, _
"Position der MessageBox", 0, 0
End Sub


Anzeige
AW: Position einer MsgBox ändern
13.07.2003 14:18:40
Lothar Ehret
Hallo Nancy,

ich habe Deinen Code probiert. Nach einer kleinen Änderung (die Variablen Check1, txtPosX und txtPosY wurden nicht gefunden; App.hInstance mußte ich durch Application.hInstance ersetzen) funktioniert er jetzt einwandfrei. Der Code in Modul 1 habe ich unverändert übernommen. Der Code von '

Private Sub Command1_Click()' wird bei mir aus einer Userform aufgerufen. Dabei ist zu beachten, daß der Code unmittelbar vor dem Aufruf der MsgBox eingefügt wird. Andernfalls kann es sein, daß das komplette Excel-Fenster verschoben wird. Anbei die Korrektur.
Nochmals tausend Dank. Du hast mir sehr weitergeholfen.
Gruß
Lothar

Private Sub Command1_Click()
Dim hInst As Long, Thread As Long
Dim msg As String
'       If Check1.Value = 1 Then
'          msg$ = "Die MessageBox ist jetzt zentriert."
'       Else
hInst = Application.Hinstance
Thread = GetCurrentThreadId()
hHook = SetWindowsHookEx(WH_CBT, AddressOf WinProc, _
hInst, Thread)
posX = CLng(50) 'in Klammer X-Koordinate eingeben
posY = CLng(350) 'in Klammer Y-Koordinate eingeben
msg$ = "Die Position der MessageBox ist an:" & _
vbCrLf & vbCrLf & "X-Position: " & posX & vbCrLf & _
"Y-Position: " & posY
'       End If
MsgBox msg$, vbOKOnly + vbInformation, _
"Position der MessageBox", 0, 0
End Sub


Anzeige
AW: Position einer MsgBox ändern
13.07.2003 21:25:03
NE
Hallo Lothar,
Danke für die Blumen & das konstruktive Posting möglicher Fehler.
(aber der Code ist really nicht von mir)
Freut' mich aber, wenn es weitergeholfen hat.
Gruss Nancy

AW: Position einer MsgBox ändern
13.07.2003 10:09:00
Lothar Ehret
Hallo Nancy,
vielen Dank für den Code. Wenn ich dazu komme, werde ich es heute Nachmittag gleich mal auschecken.
Gruß
Lothar

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige
Archiv - Verwandte Themen
Forumthread
Beiträge