Botón de minimizar y maximizar en Form de vba
En base a una pregunta del blog, encontré el siguiente código (el cual no es mi autoría) para poder poner tanto un botón de minimizar y uno de maximizar en un formulario de vba.
Ver video Haz que tus Formularios parezcan aplicaciones
El código va en el formulario. Lo comparto:
Option Explicit #If VBA7 And Win64 Then Private Declare PtrSafe Function FindWindow Lib "USER32" _ Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As LongPtr #Else Private Declare Function FindWindow Lib "USER32" _ Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long #End If #If VBA7 And Win64 Then Private Declare PtrSafe Function DrawMenuBar Lib "USER32" (ByVal hwnd As Long) As LongPtr #Else Private Declare Function DrawMenuBar Lib "USER32" (ByVal hwnd As Long) As Long #End If #If VBA7 And Win64 Then #If VBA7 Then #If Win64 Then Private Declare PtrSafe Function SetWindowLongPtr Lib "USER32" Alias "SetWindowLongPtrA" _ (ByVal hwnd As LongPtr, ByVal nIndex As Long, ByVal dwNewLong As LongPtr) As LongPtr #Else Private Declare Function SetWindowLongPtr Lib "USER32" Alias "SetWindowLongA" _ (ByVal hwnd As LongPtr, ByVal nIndex As Long, ByVal dwNewLong As LongPtr) As LongPtr #End If #Else Private Declare Function SetWindowLongPtr Lib "USER32" Alias "SetWindowLongA" _ (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long #End If #Else Private Declare Function SetWindowLong Lib "USER32" Alias "SetWindowLongA" _ (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long #End If #If VBA7 And Win64 Then #If VBA7 Then #If Win64 Then Private Declare PtrSafe Function GetWindowLongPtr Lib "USER32" _ Alias "GetWindowLongPtrA" (ByVal hwnd As LongPtr, ByVal nIndex As Long) As LongPtr #Else Private Declare PtrSafe Function GetWindowLongPtr Lib "USER32" _ Alias "GetWindowLongA" (ByVal hwnd As LongPtr, ByVal nIndex As Long) As LongPtr #End If #Else Private Declare Function GetWindowLongPtr Lib "USER32" Alias "GetWindowLongA" _ (ByVal hwnd As Long, ByVal nIndex As Long) As Long #End If #Else Private Declare Function GetWindowLong Lib "USER32" Alias "GetWindowLongA" _ (ByVal hwnd As Long, ByVal nIndex As Long) As Long #End If Private Const WS_MINIMIZEBOX As Long = &H20000 Private Const WS_MAXIMIZEBOX As Long = &H10000 Private Const GWL_STYLE As Long = (-16) 'AL INICIAR EL FORMULARIO Private Sub UserForm_Initialize() Dim Windows64 As Boolean ' 'Validamos la versión de Office #If VBA7 And Win64 Then Dim lngMyHandle As LongPtr, lngCurrentStyle As LongPtr, lngNewStyle As LongPtr #Else Dim lngMyHandle As Long, lngCurrentStyle As Long, lngNewStyle As Long #End If ' If Application.Version < 9 Then lngMyHandle = FindWindow("THUNDERXFRAME", Me.Caption) Else lngMyHandle = FindWindow("THUNDERDFRAME", Me.Caption) End If ' #If VBA7 And Win64 Then lngCurrentStyle = GetWindowLongPtr(lngMyHandle, GWL_STYLE) lngNewStyle = lngCurrentStyle Or WS_MINIMIZEBOX Or WS_MAXIMIZEBOX SetWindowLongPtr lngMyHandle, GWL_STYLE, lngNewStyle ' #Else lngCurrentStyle = GetWindowLong(lngMyHandle, GWL_STYLE) lngNewStyle = lngCurrentStyle Or WS_MINIMIZEBOX Or WS_MAXIMIZEBOX SetWindowLong lngMyHandle, GWL_STYLE, lngNewStyle #End If ' #If Win64 Then Windows64 = True #Else Windows64 = False #End If ' End Sub
:: Descargar el ejemplo
Sergio! muchas gracias por el aporte!
Pues felicita de mi parte al autor y gracias por el aporte.
Es muy interesante, me gusta lo que publicaste creo que lo recomendare, es lo que andaba buscando
Se te agradecen los comentarios.
tengo un problemita con el codigo se ejcuta normal , pero al querer usar mi formulario me sale error :'(, ingreso un codigo para buscar y me sale error
Qué error y en qué lìnea ??
hola amigo esto solo funciona en pc de 32 bits pero en 64 bits sale error.
En estos días estaré publicando la versión del código para que funcione con 64 bits.
Estate atento.
Hoy se publica un artículo al respecto.
Estate pendiente.
Hola, a mí me funciona en algunos formularios, en otros no, es decir en algunos me deja minimizar y ver otros archivos de excel pero en otros formularios no, ¿Es por el mismo error de 32 y 64 bit?
Me funciona con Windows 64
Todo esta muy bien amigo pero cuando minimizo el formulario no me deja abrir otro archivo excel. ¿existe alguna solucion?
Botón de minimizar y maximizar en Form de vba
No se puede descargar el ejemplo, da el siguiente error el link de descarga:
Runtime Error
Description: An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed remotely (for security reasons). It could, however, be viewed by browsers running on the local server machine.
Details: To enable the details of this specific error message to be viewable on remote machines, please create a tag within a “web.config” configuration file located in the root directory of the current web application. This tag should then have its “mode” attribute set to “Off”.
Listo, ya debe funcionar el link.
Buen dia Sergio, 2 cosas:
1.- Agrego tu codigo a mi formulario y el mismo se colocan todas las instrucciones en color rojo y no me corre.
2.- he tratado de descargar el complemento exceleinfo y los link estan caidos.
tengo excel 16, sistema de 32 bit y win 10, español
gracias de antemano