ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Locking the Application Window size (https://www.excelbanter.com/excel-programming/283391-locking-application-window-size.html)

Dusan

Locking the Application Window size
 
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



Vasant Nanavati

Locking the Application Window size
 
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

--

Vasant


"Dusan" <a@a wrote in message
...
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






All times are GMT +1. The time now is 12:59 AM.

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