possition of userform change on event?

C

chrisdarl

Hi, I am wanting to keep the possition of the userform the same and
was thinking of a code to add that when the mouse moves or is clicke
the left & top possition is checked and if left is not 350 and top i
not 115 then they are changed to that value.

I was thinking of something like:

If Me.Left >= 350 Or Me.Left <= 350 Or Me.Top >= 115 Or Me.Top <= 11
Then
Me.Left = 350
Me.Top = 115
End If

proberly completely wrong but can anyone give me any ideas as im no
sure where to put this?
I've tried Private sub userform_click() ect.

Many thanks Chris
 
C

chrisdarl

I have tried the code:

Option Explicit

Private Const MF_BYPOSITION As Long = &H400
Private Declare Function GetSystemMenu Lib "user32" _
(ByVal hWnd As Long, ByVal bRevert As Long) As Long
Private Declare Function DeleteMenu Lib "user32" _
(ByVal hMenu As Long, ByVal nPosition As Long, _
ByVal wFlags As Long) As Long
Private Declare Function FindWindowA Lib "user32" _
(ByVal lpClassName As String, ByVal lpWindowName _
As String) As Long

Private Sub UserForm_Initialize()
Dim lHandle As Long, lCount As Long
On Error Resume Next
lHandle = FindWindowA(vbNullString, Me.Caption)
If lHandle <> 0 Then
For lCount = 1 To 6
DeleteMenu GetSystemMenu(lHandle, False), 0, MF_BYPOSITION
Next lCount
End If
End Sub

but i recieve errors about having comments?

Can anyone give me any ideas on what im doing wrong?

Thanks Chris
 
V

Vasant Nanavati

I just tried it and it works fine for me. Where are you getting the errors
and what exactly is the wording?
 
C

chrisdarl

i am getting the following message:

"only commentsmay appear after end sub, end function, or end property


this code appears on the private declare bits of the code.


Thanks Chris
 
V

Vasant Nanavati

The Option Explicit and Private Declare statements should be at the very top
of the UserForm code module. I may have confused you by giving you the
UserForm_Activate() code first.

Option Explicit

Private Declare ...

The subs (Activate and Initialize), in any order.
 
H

Harald Staff

There is probably something below End Sub in your module. Remove that or the
code refuse to run. Your code, as pasted directly in your post, works
perfect here as is.

HTH. Best wishes Harald
 

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