Blocking Access to Sheet

E

Eddie_SP

Hi Community !

I have in my initial UserForm the following code to take all the screen:

Me.Height = Application.Height
Me.Width = Application.Width

BUT,

I've realized that users can move this UF and change the sheets with all
data behind it.

Is there any code I can use to "lock" this UserForm? So people cannot move it?

Thank yoooou !
 
M

Mike H

Hi,

This is some code I kept written by Ivan F Moala that disable the option to
move a userform

Option Explicit
Private Declare Function GetSystemMenu Lib "user32" (ByVal hWnd As Long, _
ByVal bRevert As Long) As Long
Private Declare Function RemoveMenu 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 Const MF_BYPOSITION As Long = &H400

Private Sub UserForm_Initialize()
Dim lFrmHdl As Long, iCount As Integer
lFrmHdl = FindWindowA(vbNullString, Me.Caption)
If lFrmHdl <> 0 Then
For iCount = 0 To 1
RemoveMenu GetSystemMenu(lFrmHdl, False), 0, MF_BYPOSITION
Next iCount
End If
End Sub

Mike
 
P

Patrick Molloy

you could try
Application.Visible = False

remember to set it back to visible when the form closes though

If the userform is shown modal, then they can't access any sheets
 

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