Botao fechar de uma planilha

Edu

13-05-2011 17:24:57

Teria com desabilitar o botao fechar do excel?

Mauro Coutinho

13-05-2011 23:38:40

Edu, se está falando dos Botões - Minimizar, Restaurar, e Fechar(X) na Barra do aplicativo á Direita :

No arquivo que quer, ffaça o seguinte :
Tecle ALT + F11, naJanela Propriedades do VBA do lado, de DOIS Cliques em EstaPasta_de_trabalho e cole as Rotinas abaixo :

Código: Selecionar todos

Private Sub Workbook_Open()
    Application.ScreenUpdating = False
        RetirarMenuControle32
    Application.ScreenUpdating = True
End Sub

Private Sub Workbook_BeforeClose(Cancel As Boolean)
    AplicarMenuControle32
End Sub
Depois crie um Módulo e cole estas :

Código: Selecionar todos

Option Explicit

Declare Function FindWindow32 Lib "user32" Alias "FindWindowA" _
        (ByVal lpClassName As Any, ByVal lpWindowName As Any) As Integer
Declare Function GetWindowLong32 Lib "user32" Alias "GetWindowLongA" _
        (ByVal hWnd As Integer, ByVal nIndex As Integer) As Long
Declare Function SetWindowLong32 Lib "user32" Alias "SetWindowLongA" _
        (ByVal hWnd As Integer, ByVal nIndex As Integer, _
        ByVal dwNewLong As Long) As Long
        
Global Const GWL_STYLE = (-16)
Global Const WS_SYSMENU = &H80000

Sub AplicarMenuControle32()
    Dim WindowStyle As Long
    Dim hWnd As Integer
    Dim WindowName As String
    Dim Result As Variant
    
    WindowName = Application.Caption
    
    hWnd = FindWindow32(0&, ByVal WindowName)
    WindowStyle = GetWindowLong32(hWnd, GWL_STYLE)
    WindowStyle = WindowStyle Or WS_SYSMENU
    Result = SetWindowLong32(hWnd, GWL_STYLE, WindowStyle)
    
    ActiveSheet.Activate

End Sub

Sub RetirarMenuControle32()
    Dim WindowStyle As Long
    Dim hWnd As Integer
    Dim WindowName As String
    Dim Result As Variant
    
    WindowName = Application.Caption
    
    hWnd = FindWindow32(0&, ByVal WindowName)
    WindowStyle = GetWindowLong32(hWnd, GWL_STYLE)
    WindowStyle = WindowStyle And (Not WS_SYSMENU)
    Result = SetWindowLong32(hWnd, GWL_STYLE, WindowStyle)

    ActiveSheet.Activate

End Sub
Quando o arquivo for aberto os botões serão retirados e repostos quando fechar, lembrando que estas não funcionam no Excel 2007.

abraços