Saberexcel - Site de quem precisa Aprender Macros Microsoft Excel VBA
Essas declarações e procedimentos do Aplicativo Microsoft Excel VBA, impede o usuário de mover o userform (formulário) pela folha de planilha, tornando-o estático, imóvel.
Private Declare Function RemoveMenu _
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 Declare Function GetSystemMenu Lib "user32" (ByVal hWnd As Long, _
ByVal bRevert As Long) As Long
Private Const MF_BYPOSITION As Long = &H400
Private Sub CommandButton1_Click()
Unload Me
End Sub
Private Sub UserForm_Initialize()
Dim lFrmHdl As Long, iCount As Integer
lFrmHdl = FindWindowA(vbNullString, Me.Caption)
If lFrmHdl <> 0 Then
'MF_BYCOMMAND
'Indicates that uPosition gives the identifier of the menu item.
'If neither the MF_BYCOMMAND nor MF_BYPOSITION flag is specified,
'the MF_BYCOMMAND flag is the default flag.
'MF_BYPOSITION
'Indicates that uPosition gives the zero-based relative position of the menu item.
'ie 0,1,2,3 etc
'Exit Sub
'Typical Windows has 6 menus
'Restore, Move, Size, Minimise, Maximize, Close
'Even though a Userform displays 2 = Move & Close
'By default Move is the Next item
'so just loop twice
For iCount = 0 To 1
RemoveMenu GetSystemMenu(lFrmHdl, False), 0, MF_BYPOSITION
Next iCount
End If
End Sub
Aprenda tudo sobre planilhas do Aplicativo Microsoft Excel VBA(Visual Basic Application), sozinho, com baixo custo, praticando com os produtos didáticos Saberexcel
Baixe o exemplo de planilha contendo as declarações e procedimentos acima
Excel planilha vba usf formulario fixo na folha de planilha (20.66 kB)