ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Position of MsgBox (https://www.excelbanter.com/excel-programming/411075-position-msgbox.html)

Otto Moehrbach[_2_]

Position of MsgBox
 
Excel XP & 2007
An OP has asked me if there is a way to control the position of a MsgBox on
the screen. I know of no way to do that. Is that possible? Thanks for
your time. Otto



Ken

Position of MsgBox
 
Otto

Someone may know how to control the position of a msgbox, but, it
would be pretty easy to control the position of a userform that looks
and acts like a msgbox; in case that will work.

Ken


On May 16, 3:07*pm, "Otto Moehrbach"
wrote:
Excel XP & 2007
An OP has asked me if there is a way to control the position of a MsgBox on
the screen. *I know of no way to do that. *Is that possible? *Thanks for
your time. *Otto



Gary''s Student

Position of MsgBox
 
See:

http://groups.google.com/group/micro...c6d98b98fb7aca
--
Gary''s Student - gsnu2007h


"Otto Moehrbach" wrote:

Excel XP & 2007
An OP has asked me if there is a way to control the position of a MsgBox on
the screen. I know of no way to do that. Is that possible? Thanks for
your time. Otto




Peter T

Position of MsgBox
 
I think Stratos posted that more as an academic exercise rather than as his
suggested way to position a msgbox, and very clever it is too. He also said
"Therefore my suggestion would be if you
really need to position a message box use a userform or a baloon instead."

He did explain the code was for use in XL97 and as written it will only work
in XL97, later versions will not find vba332.dll. That library is only
required as part of the workaround for AddressOf which was n/a in xl97. In
later versions, in the function fncMsgBox_Pos97 include the following.

#If VBA6 Then
TempHook = SetWindowsHookEx _
( _
idHook:=WH_CBT, _
lpfn:=AddressOf cbkPositionMsgBox, _
hmod:=GetWindowLong(0, GWL_HINSTANCE), _
dwThreadId:=GetCurrentThreadId() _
)

#Else
TempHook = SetWindowsHookEx _
( _
idHook:=WH_CBT, _
lpfn:=AddrOf("cbkPositionMsgBox"), _
hmod:=GetWindowLong(0, GWL_HINSTANCE), _
dwThreadId:=GetCurrentThreadId() _
)
#End If

If no need to cater for xl97 remove the conditional #If, the AddrOf
function, and Declare Function GetCurrentVbaProject from the top of the
module.

Follow instructions carefully about where to put code and how to run (not in
the IDE, at least don't try to step through). Don't forget to add the
FindWindow API that was initially overlooked.

Regards,
Peter T


"Gary''s Student" wrote in message
...
See:


http://groups.google.com/group/micro...c6d98b98fb7aca
--
Gary''s Student - gsnu2007h


"Otto Moehrbach" wrote:

Excel XP & 2007
An OP has asked me if there is a way to control the position of a MsgBox

on
the screen. I know of no way to do that. Is that possible? Thanks for
your time. Otto






Gary''s Student

Position of MsgBox
 
Peter:

Might it be possible to first create the MsgBox (where ever Excel want to
put it) and then move it to some location with VBA??
--
Gary''s Student - gsnu200786


"Peter T" wrote:

I think Stratos posted that more as an academic exercise rather than as his
suggested way to position a msgbox, and very clever it is too. He also said
"Therefore my suggestion would be if you
really need to position a message box use a userform or a baloon instead."

He did explain the code was for use in XL97 and as written it will only work
in XL97, later versions will not find vba332.dll. That library is only
required as part of the workaround for AddressOf which was n/a in xl97. In
later versions, in the function fncMsgBox_Pos97 include the following.

#If VBA6 Then
TempHook = SetWindowsHookEx _
( _
idHook:=WH_CBT, _
lpfn:=AddressOf cbkPositionMsgBox, _
hmod:=GetWindowLong(0, GWL_HINSTANCE), _
dwThreadId:=GetCurrentThreadId() _
)

#Else
TempHook = SetWindowsHookEx _
( _
idHook:=WH_CBT, _
lpfn:=AddrOf("cbkPositionMsgBox"), _
hmod:=GetWindowLong(0, GWL_HINSTANCE), _
dwThreadId:=GetCurrentThreadId() _
)
#End If

If no need to cater for xl97 remove the conditional #If, the AddrOf
function, and Declare Function GetCurrentVbaProject from the top of the
module.

Follow instructions carefully about where to put code and how to run (not in
the IDE, at least don't try to step through). Don't forget to add the
FindWindow API that was initially overlooked.

Regards,
Peter T


"Gary''s Student" wrote in message
...
See:


http://groups.google.com/group/micro...c6d98b98fb7aca
--
Gary''s Student - gsnu2007h


"Otto Moehrbach" wrote:

Excel XP & 2007
An OP has asked me if there is a way to control the position of a MsgBox

on
the screen. I know of no way to do that. Is that possible? Thanks for
your time. Otto







Otto Moehrbach[_2_]

Position of MsgBox
 
Yes. How is that done? Otto
"Gary''s Student" wrote in message
...
Peter:

Might it be possible to first create the MsgBox (where ever Excel want to
put it) and then move it to some location with VBA??
--
Gary''s Student - gsnu200786


"Peter T" wrote:

I think Stratos posted that more as an academic exercise rather than as
his
suggested way to position a msgbox, and very clever it is too. He also
said
"Therefore my suggestion would be if you
really need to position a message box use a userform or a baloon
instead."

He did explain the code was for use in XL97 and as written it will only
work
in XL97, later versions will not find vba332.dll. That library is only
required as part of the workaround for AddressOf which was n/a in xl97.
In
later versions, in the function fncMsgBox_Pos97 include the following.

#If VBA6 Then
TempHook = SetWindowsHookEx _
( _
idHook:=WH_CBT, _
lpfn:=AddressOf cbkPositionMsgBox, _
hmod:=GetWindowLong(0, GWL_HINSTANCE), _
dwThreadId:=GetCurrentThreadId() _
)

#Else
TempHook = SetWindowsHookEx _
( _
idHook:=WH_CBT, _
lpfn:=AddrOf("cbkPositionMsgBox"), _
hmod:=GetWindowLong(0, GWL_HINSTANCE), _
dwThreadId:=GetCurrentThreadId() _
)
#End If

If no need to cater for xl97 remove the conditional #If, the AddrOf
function, and Declare Function GetCurrentVbaProject from the top of the
module.

Follow instructions carefully about where to put code and how to run (not
in
the IDE, at least don't try to step through). Don't forget to add the
FindWindow API that was initially overlooked.

Regards,
Peter T


"Gary''s Student" wrote in
message
...
See:


http://groups.google.com/group/micro...c6d98b98fb7aca
--
Gary''s Student - gsnu2007h


"Otto Moehrbach" wrote:

Excel XP & 2007
An OP has asked me if there is a way to control the position of a
MsgBox

on
the screen. I know of no way to do that. Is that possible? Thanks
for
your time. Otto









Gary''s Student

Position of MsgBox
 
When I thought about the problem with more coffee in me, I realized that
there is a sort of Catch-22. Once the VBA has popped up the MsgBox, it has
lost focus ("sleeping"), waiting for the user to respond. Anyway here is
another reference:

http://groups.google.com/group/micro...26b8c4f39aa019
--
Gary''s Student - gsnu200786


"Otto Moehrbach" wrote:

Yes. How is that done? Otto
"Gary''s Student" wrote in message
...
Peter:

Might it be possible to first create the MsgBox (where ever Excel want to
put it) and then move it to some location with VBA??
--
Gary''s Student - gsnu200786


"Peter T" wrote:

I think Stratos posted that more as an academic exercise rather than as
his
suggested way to position a msgbox, and very clever it is too. He also
said
"Therefore my suggestion would be if you
really need to position a message box use a userform or a baloon
instead."

He did explain the code was for use in XL97 and as written it will only
work
in XL97, later versions will not find vba332.dll. That library is only
required as part of the workaround for AddressOf which was n/a in xl97.
In
later versions, in the function fncMsgBox_Pos97 include the following.

#If VBA6 Then
TempHook = SetWindowsHookEx _
( _
idHook:=WH_CBT, _
lpfn:=AddressOf cbkPositionMsgBox, _
hmod:=GetWindowLong(0, GWL_HINSTANCE), _
dwThreadId:=GetCurrentThreadId() _
)

#Else
TempHook = SetWindowsHookEx _
( _
idHook:=WH_CBT, _
lpfn:=AddrOf("cbkPositionMsgBox"), _
hmod:=GetWindowLong(0, GWL_HINSTANCE), _
dwThreadId:=GetCurrentThreadId() _
)
#End If

If no need to cater for xl97 remove the conditional #If, the AddrOf
function, and Declare Function GetCurrentVbaProject from the top of the
module.

Follow instructions carefully about where to put code and how to run (not
in
the IDE, at least don't try to step through). Don't forget to add the
FindWindow API that was initially overlooked.

Regards,
Peter T


"Gary''s Student" wrote in
message
...
See:


http://groups.google.com/group/micro...c6d98b98fb7aca
--
Gary''s Student - gsnu2007h


"Otto Moehrbach" wrote:

Excel XP & 2007
An OP has asked me if there is a way to control the position of a
MsgBox
on
the screen. I know of no way to do that. Is that possible? Thanks
for
your time. Otto










Peter T

Position of MsgBox
 
As you say, code is suspended until the msgbox is dismissed. Did either of
you actually try the demo by Stratos. I only ask because your similar
questions implied either you didn't or you couldn't get it to work. It
worked fine for me after adapting for post xl97 versions along the lines I
suggested.

Although the demo in the link below (by Jim Rech) looks different, in
essence the hook method is pretty much the same. Jim's includes an
extra"feature" in that it returns the size of the msgbox, so with a bit of
math's would allow the msgbox to be centred over a userform, for example.

Regards,
Peter T

"Gary''s Student" wrote in message
...
When I thought about the problem with more coffee in me, I realized that
there is a sort of Catch-22. Once the VBA has popped up the MsgBox, it

has
lost focus ("sleeping"), waiting for the user to respond. Anyway here is
another reference:


http://groups.google.com/group/micro...26b8c4f39aa019
--
Gary''s Student - gsnu200786


"Otto Moehrbach" wrote:

Yes. How is that done? Otto
"Gary''s Student" wrote in

message
...
Peter:

Might it be possible to first create the MsgBox (where ever Excel want

to
put it) and then move it to some location with VBA??
--
Gary''s Student - gsnu200786


"Peter T" wrote:

I think Stratos posted that more as an academic exercise rather than

as
his
suggested way to position a msgbox, and very clever it is too. He

also
said
"Therefore my suggestion would be if you
really need to position a message box use a userform or a baloon
instead."

He did explain the code was for use in XL97 and as written it will

only
work
in XL97, later versions will not find vba332.dll. That library is

only
required as part of the workaround for AddressOf which was n/a in

xl97.
In
later versions, in the function fncMsgBox_Pos97 include the

following.

#If VBA6 Then
TempHook = SetWindowsHookEx _
( _
idHook:=WH_CBT, _
lpfn:=AddressOf cbkPositionMsgBox, _
hmod:=GetWindowLong(0, GWL_HINSTANCE), _
dwThreadId:=GetCurrentThreadId() _
)

#Else
TempHook = SetWindowsHookEx _
( _
idHook:=WH_CBT, _
lpfn:=AddrOf("cbkPositionMsgBox"), _
hmod:=GetWindowLong(0, GWL_HINSTANCE), _
dwThreadId:=GetCurrentThreadId() _
)
#End If

If no need to cater for xl97 remove the conditional #If, the AddrOf
function, and Declare Function GetCurrentVbaProject from the top of

the
module.

Follow instructions carefully about where to put code and how to run

(not
in
the IDE, at least don't try to step through). Don't forget to add the
FindWindow API that was initially overlooked.

Regards,
Peter T


"Gary''s Student" wrote in
message
...
See:



http://groups.google.com/group/micro...c6d98b98fb7aca
--
Gary''s Student - gsnu2007h


"Otto Moehrbach" wrote:

Excel XP & 2007
An OP has asked me if there is a way to control the position of a
MsgBox
on
the screen. I know of no way to do that. Is that possible?

Thanks
for
your time. Otto













All times are GMT +1. The time now is 01:03 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com