1

Preciso trabalhar com alguns formulários sem a barra de títulos no VBA/Excel.

Encontrei muitas soluções similares, mas todas para 32 bits (principalmente em versões antigas do VBA).

As indicações que deram para adaptar para 64 bits eu não consegui fazer funcionar.

Como fazer para 64 bits?

1
  • Ok, vou remover meu voto pra fechar e apagar os comentários. Faça o mesmo, ok? 23/08/2016 às 0:00

1 Resposta 1

1

Encontrei a solução em um site nacional e a adaptei.

A referência que tomei por base para o formulário sem a barra de títulos (chamada por cabeçalho no site) foi do: Saber Excel.

Excel planilha vba userform sem cabecalho

Apresento a seguir o código com a solução:

Option Explicit

' Fonte: Saber Excel
'
' http://www.microsoftexcel.com.br/index.php/excel-dicas-microsoft-excel-vba/185-excel-vba-userforms-e-outros/1225-excel-planilha-vba-userform-sem-cabecalho.html

'======================================================================================================================================
' Retira o cabeçalho do Formulário completamente
'======================================================================================================================================

Private Type RECT
        Left As Long
        Top As Long
        Right As Long
        Bottom As Long
End Type

Const GWL_STYLE = (-16)
Const WS_CAPTION = &HC00000
Const SWP_FRAMECHANGED = &H20

Private Declare Function FindWindowA Lib "user32" _
       (ByVal lpClassName As String, _
        ByVal lpWindowName As String) _
     As Long

Private Declare Function GetWindowRect Lib "user32" _
      (ByVal hwnd As Long, lpRect As RECT) _
     As Long

Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" _
       (ByVal hwnd As Long, _
        ByVal nIndex As Long) _
     As Long

Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _
       (ByVal hwnd As Long, ByVal nIndex As Long, _
        ByVal dwNewLong As Long) _
     As Long

Private Declare Function SetWindowPos Lib "user32" _
       (ByVal hwnd As Long, _
        ByVal hWndInsertAfter As Long, _
        ByVal X As Long, _
        ByVal Y As Long, _
        ByVal cx As Long, _
        ByVal cy As Long, _
        ByVal wFlags As Long) _
     As Long

Sub RETIRAR_CABECALHO_SABEREXCEL(stCaption As String, sbxVisible As Boolean)
Dim vrWin As RECT
Dim style As Long
Dim lHwnd As Long
    lHwnd = FindWindowA(vbNullString, stCaption)
    GetWindowRect lHwnd, vrWin
    style = GetWindowLong(lHwnd, GWL_STYLE)
    If sbxVisible Then
        SetWindowLong lHwnd, GWL_STYLE, style Or WS_CAPTION
    Else
        SetWindowLong lHwnd, GWL_STYLE, style And Not WS_CAPTION
    End If
    SetWindowPos lHwnd, 0, vrWin.Left, vrWin.Top, vrWin.Right - vrWin.Left, _
                 vrWin.Bottom - vrWin.Top, SWP_FRAMECHANGED
End Sub


Private Sub UserForm_Initialize()

RETIRAR_CABECALHO_SABEREXCEL Me.Caption, False

End Sub


Private Sub ButtonSair_Click()

Unload Me

End Sub

Como o formulário fica sem a barra de títulos, foi preciso colocar um botão para "sair" do formulário.

Também dá para fechá-lo com Alt+F4.

Você deve fazer log-in para responder a esta pergunta.

Esta não é a resposta que você está procurando? Pesquise outras perguntas com a tag .