Modeless form takes 'focus'

M

Michelle

I am displaying a modeless form, and I want the user to be able to continue
to use Excel seamlessly while it's on the screen.

However, the form sort of 'takes focus'. In practical terms it means that
rolling the wheel on the mouse doesn't scroll the spreadsheet until you
'click-away' from the form.

To scroll normally, I have to click the sheet (behind the form), and then it
works fine. But is there a code command that will 'set focus' back to the
application - i.e. dim the title-bar on the form and make the application
'active'. Do you know what I mean?

I hope that makes sense

Thanks

M
 
J

Jacob Skaria

Hi Michelle

One way is to control the mouse using code. Try the below and feedback. You
will need to adjust the cursor positions to suit your requirement (it the
below does not work).

--Insert a module and copy the below declarations.
'---------------------------------------------------------------------------------
Declare Function SetCursorPos Lib "user32" _
(ByVal x As Long, ByVal y As Long) As Long
Public Declare Sub mouse_event Lib "user32" _
(ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, _
ByVal cButtons As Long, ByVal dwExtraInfo As Long)
Public Declare Function GetMessageExtraInfo Lib "user32" () As Lon
'---------------------------------------------------------------------------------

--Copy the below code to Userform initialize event

Private Sub UserForm_Initialize()
SetCursorPos 150, 200
mouse_event &H2, 0, 0, 0, GetMessageExtraInfo()
mouse_event &H4, 0, 0, 0, GetMessageExtraInfo()
End Sub


If this post helps click Yes
 
H

Homey

this work for me. I use Win XP dont know if work in vista.

Public Declare Function SetForegroundWindow Lib "user32" (ByVal hWnd As
Long) As Long

Sub ShowUFModelessNoFocus()
UserForm1.Show False
SetForegroundWindow Application.hWnd
End Sub

|I am displaying a modeless form, and I want the user to be able to continue
| to use Excel seamlessly while it's on the screen.
|
| However, the form sort of 'takes focus'. In practical terms it means that
| rolling the wheel on the mouse doesn't scroll the spreadsheet until you
| 'click-away' from the form.
|
| To scroll normally, I have to click the sheet (behind the form), and then
it
| works fine. But is there a code command that will 'set focus' back to the
| application - i.e. dim the title-bar on the form and make the application
| 'active'. Do you know what I mean?
|
| I hope that makes sense
|
| Thanks
|
| M
|
 
M

Michelle

Bloody marvellous! - I've been trying to do this for ages and this is
fabulously simple - Thank you.

M
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top