Notifications
Clear all

Travar tamanho pre definido da janela do Excel com VBA

4 Posts
2 Usuários
0 Reactions
1,464 Visualizações
(@veni_veni)
Posts: 0
New Member
Topic starter
 

Boa tarde galera!
Estou com a seguinte situação:
Tenho uma planilha, e quero que ela inicialize em um tamanho pre definido.
Conseguir isso com a aplicação windows.
Porem, quero que a janela fique travada, não sendo possível redimensioná ou entrar em modo full screen. Em resumo preciso de uma função que bloqueia o botão maximizar do exel, e de outra que impeça o redimensionamento da janela.
Será que alguém pode me ajudar?

 
Postado : 23/10/2014 1:54 pm
(@fernandofernandes)
Posts: 43750
Illustrious Member
 

Boa tarde!!

Public Const WS_MINIMIZEBOX = &H20000
Public Const WS_MAXIMIZEBOX = &H10000

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 Sub Prevent_Window_Resize()

    Dim hWnd As Long
    Dim style As Long
    Dim ret As Long
    
    hWnd = Application.hWnd
        
    style = GetWindowLong(hWnd, GWL_STYLE)
    
    'From http://support.microsoft.com/kb/133256
    'Remove the thick frame style and the Minimise and Maximise buttons
    
    style = style And Not (WS_THICKFRAME Or WS_MAXIMIZEBOX Or WS_MINIMIZEBOX)
    ret = SetWindowLong(hWnd, GWL_STYLE, style)
    
End Sub

Não testado!!

Att

 
Postado : 23/10/2014 2:01 pm
(@veni_veni)
Posts: 0
New Member
Topic starter
 

alexandrevba
Obrigado pela resposta!
O Exel para de funcionar ao executar o codigo.
E quando executa, simplesmente nao acontece nada!

 
Postado : 23/10/2014 2:25 pm
(@veni_veni)
Posts: 0
New Member
Topic starter
 

Consegui:
Alem de impedir o redimensionamento, exclui os botoes maximizar e minimizar
Segue o código como ficou

Option Explicit

Public Const GWL_STYLE = (-16)
Public Const WS_THICKFRAME = &H40000
Public Const WS_MINIMIZEBOX = &H20000
Public Const WS_MAXIMIZEBOX = &H10000

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 Sub Prevent_Window_Resize()

    Dim hWnd As Long
    Dim style As Long
    Dim ret As Long
    
    hWnd = Application.hWnd
        
    style = GetWindowLong(hWnd, GWL_STYLE)
    
    'From http://support.microsoft.com/kb/133256
    'Remove the thick frame style and the Minimise and Maximise buttons
    
    style = style And Not (WS_THICKFRAME Or WS_MAXIMIZEBOX Or WS_MINIMIZEBOX)
    ret = SetWindowLong(hWnd, GWL_STYLE, style)
    
End Sub

Valeu cara!
Att

 
Postado : 23/10/2014 2:41 pm