RE:bloquear barra de titulo
En un modulo "normal":
Option Explicit
Public Declare Function GetSystemMenu Lib "user32" (ByVal hWnd As Long, ByVal bRevert As Long) As Long
Public Declare Function GetMenuItemCount Lib "user32" (ByVal hMenu As Long) As Long
Public Declare Function RemoveMenu Lib "user32" (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long) As Long
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Const MF_BYPOSITION = &H400&
Public Const MF_REMOVE = &H1000&
Public blnCerrar As Boolean
'---------------------------------------------------------
' EnableControlBox
' EnableMinimizeBox
' EnableMaximizeBox
'
' Código escrito originalmente por Juan M Afán de Ribera.
' Estás autorizado a utilizarlo dentro de una aplicación
' siempre que esta nota de autor permanezca inalterada.
' En el caso de querer publicarlo en una página Web,
' por favor, contactar con el autor en
'
' ExcelvbaAlGaRroBayaPuNtOcom
'
' Este código se brinda por cortesía de
' Juan M. Afán de Ribera
' Modificado por ESH 15/03/05 16:15 para adaptarlo a Excel
Public Declare Function GetWindowLong Lib "user32" _
Alias "GetWindowLongA" _
(ByVal hWnd As Long, _
ByVal nIndex As Long) As Long
Public Declare Function SetWindowLong Lib "user32" _
Alias "SetWindowLongA" _
(ByVal hWnd As Long, _
ByVal nIndex As Long, _
ByVal dwNewLong As Long) As Long
Public Declare Function DrawMenuBar _
Lib "user32" _
(ByVal hWnd As Long) As Long
Public Declare Function FindWindowEx Lib "user32" _
Alias "FindWindowExA" _
(ByVal hWnd1 As Long, _
ByVal hWnd2 As Long, _
ByVal lpsz1 As String, _
ByVal lpsz2 As String) As Long
Public Const WS_SYSMENU = &H80000
Public Const WS_MAXIMIZEBOX = &H10000
Public Const WS_MINIMIZEBOX = &H20000
Public Const GWL_STYLE = (-16)
' hace aparecer/desaparecer todo el cuadro de
' control de la ventana principal de Excel
Sub EnableControlBox(Enable As Boolean)
Dim CurStyle As Long
Dim hWnd As Long
hWnd = Application.hWnd
CurStyle = GetWindowLong(hWnd, GWL_STYLE)
If Enable Then
If Not (CurStyle And WS_SYSMENU) Then
CurStyle = CurStyle Or WS_SYSMENU
End If
Else
If (CurStyle And WS_SYSMENU) = WS_SYSMENU Then
CurStyle = CurStyle - WS_SYSMENU
End If
End If
Call SetWindowLong(hWnd, GWL_STYLE, CurStyle)
Call DrawMenuBar(hWnd)
End Sub
' activa/desactiva el botón minimizar de la
' ventana principal de Excel
Sub EnableMinimizeBox(Enable As Boolean)
Dim CurStyle As Long
Dim hWnd As Long
hWnd = Application.hWnd
CurStyle = GetWindowLong(hWnd, GWL_STYLE)
If Enable Then
If Not (CurStyle And WS_MINIMIZEBOX) Then
CurStyle = CurStyle Or WS_MINIMIZEBOX
End If
Else
If (CurStyle And WS_MINIMIZEBOX) = WS_MINIMIZEBOX Then
CurStyle = CurStyle - WS_MINIMIZEBOX
End If
End If
Call SetWindowLong(hWnd, GWL_STYLE, CurStyle)
Call DrawMenuBar(hWnd)
End Sub
' activa/desactiva el botón maximizar de la
' ventana principal de Excel
Sub EnableMaximizeBox(Enable As Boolean)
Dim CurStyle As Long
Dim hWnd As Long
hWnd = Application.hWnd
CurStyle = GetWindowLong(hWnd, GWL_STYLE)
If Enable Then
If Not (CurStyle And WS_MAXIMIZEBOX) Then
CurStyle = CurStyle Or WS_MAXIMIZEBOX
End If
Else
If (CurStyle And WS_MAXIMIZEBOX) = WS_MAXIMIZEBOX Then
CurStyle = CurStyle - WS_MAXIMIZEBOX
End If
End If
Call SetWindowLong(hWnd, GWL_STYLE, CurStyle)
Call DrawMenuBar(hWnd)
End Sub
' devuelve el hwnd de la ventana del Libro
Function hWorkbook() As Long
Dim hDesk As Long
Dim hWBook As Long
hDesk = FindWindowEx(Application.hWnd, 0&, "XLDESK", vbNullString)
If hDesk Then
hWBook = FindWindowEx(hDesk, 0&, "EXCEL7", vbNullString)
hWorkbook = hWBook
End If
End Function
' activa/desactiva todo el cuadro de control del libro Excel
Sub EnableControlBoxWB(Enable As Boolean)
Dim CurStyle As Long
Dim hWnd As Long
hWnd = hWorkbook
CurStyle = GetWindowLong(hWnd, GWL_STYLE)
If Enable Then
If Not (CurStyle And WS_SYSMENU) Then
CurStyle = CurStyle Or WS_SYSMENU
End If
Else
If (CurStyle And WS_SYSMENU) = WS_SYSMENU Then
CurStyle = CurStyle - WS_SYSMENU
End If
End If
Call SetWindowLong(hWnd, GWL_STYLE, CurStyle)
Call DrawMenuBar(hWnd)
End Sub
' activa/desactiva todo el botón minimizar del libro Excel
Sub EnableMinimizeBoxWB(Enable As Boolean)
Dim CurStyle As Long
Dim hWnd As Long
hWnd = hWorkbook
CurStyle = GetWindowLong(hWnd, GWL_STYLE)
If Enable Then
If Not (CurStyle And WS_MINIMIZEBOX) Then
CurStyle = CurStyle Or WS_MINIMIZEBOX
End If
Else
If (CurStyle And WS_MINIMIZEBOX) = WS_MINIMIZEBOX Then
CurStyle = CurStyle - WS_MINIMIZEBOX
End If
End If
Call SetWindowLong(hWnd, GWL_STYLE, CurStyle)
Call DrawMenuBar(hWnd)
End Sub
' activa/desactiva todo el botón maximizar del libro Excel
Sub EnableMaximizeBoxWB(Enable As Boolean)
Dim CurStyle As Long
Dim hWnd As Long
hWnd = hWorkbook
CurStyle = GetWindowLong(hWnd, GWL_STYLE)
If Enable Then
If Not (CurStyle And WS_MAXIMIZEBOX) Then
CurStyle = CurStyle Or WS_MAXIMIZEBOX
End If
Else
If (CurStyle And WS_MAXIMIZEBOX) = WS_MAXIMIZEBOX Then
CurStyle = CurStyle - WS_MAXIMIZEBOX
End If
End If
Call SetWindowLong(hWnd, GWL_STYLE, CurStyle)
Call DrawMenuBar(hWnd)
End Sub
'---------------------------------------------------------
En el modulo del libro:
Option Explicit
'*******************************************************************************
'* Workbook_BeforeClose
'* Impido que se cierre si la variable blnCerrar no es Verdadero
'* Argumentos:
'* uso: Workbook_BeforeClose
'* ESH 15/04/05 15:33
'*******************************************************************************
Private Sub Workbook_BeforeClose(Cancel As Boolean)
If Not blnCerrar Then Cancel = True
End Sub
'*******************************************************************************
'* Workbook_Open
'* Al abrir elimino los botones Cerrar, Maximizar y Minimizar
'* Argumentos:
'* uso: Workbook_Open
'* ESH 15/04/05 16:28
'*******************************************************************************
Private Sub Workbook_Open()
' elimino los botones Cuadro de Control, Minimizar y Maximizar de la aplicación
EnableControlBox False
EnableMinimizeBox False
EnableMaximizeBox False
' maximizo el libro
ActiveWindow.WindowState = xlMaximized
' elimino los botones Cuadro de Control, Minimizar y Maximizar del libro
EnableControlBoxWB False
EnableMinimizeBoxWB False
EnableMaximizeBoxWB False
End Sub
En un objeto (un boton por ejm), para ´poder cerrar:
' solo puedo cerrar si blnCerrar es verdadero
blnCerrar = True
Application.Quit
Abraham