No funciona minimizar

Buenas Tardes. Tengo este código que recopile de esta pagina, pero no me funciona arroja el siguiente mensaje: los comentarios solamente pueden aparecer después de end sub,end function o end property.

Private Sub UserForm_Click()
'Code to add a miminise and maximice button to a VBA userform
'Daniel Klann 13th June 2002
'Windows API functions we need to use to achieve this
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function DrawMenuBar Lib "user32" (ByVal hWnd 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 GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long
'Constants used within the API functions above
Private Const WS_MINIMIZEBOX As Long = &H20000
Private Const WS_MAXIMIZEBOX As Long = &H10000
Private Const GWL_STYLE As Long = (-16)
Private Sub UserForm_Initialize()
Dim lngMyHandle As Long, lngCurrentStyle As Long, lngNewStyle As Long
'Get the Windows handle of the userform - required for the API calls
If Application.Version < 9 Then
lngMyHandle = FindWindow("THUNDERXFRAME", Me.Caption) 'For Excel 97
Else
lngMyHandle = FindWindow("THUNDERDFRAME", Me.Caption) 'For Excel 2000 onwards
End If
'Get the current style of the userform
lngCurrentStyle = GetWindowLong(lngMyHandle, GWL_STYLE)
'Create a new style with max and min buttons
lngNewStyle = lngCurrentStyle Or WS_MINIMIZEBOX Or WS_MAXIMIZEBOX
'Apply it to the userform
SetWindowLong lngMyHandle, GWL_STYLE, lngNewStyle
End Sub

tengo office 2003

1 respuesta

Respuesta
1

El primer problema que veo en el código es que tienes abierto un "sub" en la primera línea, que no se cierra:

Private Sub UserForm_Click()

Por otro lado, la definición de las funciones externas (Private Declare Function) debe ponerse delante de cualquier "sub" o "function", por lo que empezar con la instrucción anterior, aunque tuviera el "end sub", te provocaría ese error.

La solución es sencilla: coloca el "sub" después de todas las declaraciones.

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas