Locking the Application Window size

D

Dusan

Hi there,

I have a question regarding the window size.
I'd like to define the application window size which I've done by:

Application.WindowState = xlNormal
Application.Left = 0
Application.Top = 0
Application.Width = 770
Application.Height = 484

ActiveWindow.WindowState = xlMaximized
ActiveWorkbook.Protect , True , True


Now I want to lock application window size and prevent users to change it.
Only minimizing and restoring to defined size would be possible.

It's possible to lock the workbook window size but not the application
window.
The command:

Application.Protect , True, True

simply does not exist.

There must be some other way to lock application window size.
Any help aapreciated.

Thank you
Dusan
 
V

Vasant Nanavati

You need to do this with API calls:

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 DisableSelectedSystemMenuItems()
Dim lHandle As Long, lCount As Long
On Error Resume Next
lHandle = FindWindowA(vbNullString, Application.Caption)
If lHandle <> 0 Then
DeleteMenu GetSystemMenu(lHandle, False), 1, MF_BYPOSITION
DeleteMenu GetSystemMenu(lHandle, False), 1, MF_BYPOSITION
DeleteMenu GetSystemMenu(lHandle, False), 2, MF_BYPOSITION
End If
End Sub

Private Sub ReenableSystemMenu()
Dim lHandle As Long
On Error Resume Next
lHandle = FindWindowA(vbNullString, Application.Caption)
GetSystemMenu lHandle, True
End Sub
 

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