Quitar la "X" en la ventana de una userform

rguez

Board Regular
Joined
Jul 24, 2002
Messages
78
Hola

Necesto saber como hacer para que no aparezca la "X" (que cierra la ventana) en una userform.

Gracias
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
La más facil es usar el evento QueryClose así:
<pre><FONT COLOR="#00007F">Private Sub</FONT> UserForm_QueryClose(Cancel <FONT COLOR="#00007F">As</FONT> <FONT COLOR="#00007F">Integer</FONT>, CloseMode <FONT COLOR="#00007F">As</FONT> <FONT COLOR="#00007F">Integer</FONT>)
<FONT COLOR="#00007F">If</FONT> CloseMode = 0 <FONT COLOR="#00007F">Then</FONT> Cancel = <FONT COLOR="#00007F">True</FONT>
<FONT COLOR="#00007F">End</FONT> <FONT COLOR="#00007F">Sub</FONT></pre>
Así, la "X" no sirve. Si se quiere quitar, hay que usar unas funciones API

Algo así:

<pre><FONT COLOR="#00007F">Option</FONT> <FONT COLOR="#00007F">Explicit</FONT>

<FONT COLOR="#00007F">Private</FONT> <FONT COLOR="#00007F">Declare</FONT> <FONT COLOR="#00007F">Function</FONT> FindWindow <FONT COLOR="#00007F">Lib</FONT> "user32" Alias "FindWindowA" (<FONT COLOR="#00007F">ByVal</FONT> lpClassName <FONT COLOR="#00007F">As</FONT> <FONT COLOR="#00007F">String</FONT>, <FONT COLOR="#00007F">ByVal</FONT> lpWindowName <FONT COLOR="#00007F">As</FONT> <FONT COLOR="#00007F">String</FONT>) <FONT COLOR="#00007F">As</FONT> <FONT COLOR="#00007F">Long</FONT>
<FONT COLOR="#00007F">Private</FONT> <FONT COLOR="#00007F">Declare</FONT> <FONT COLOR="#00007F">Function</FONT> GetWindowLong <FONT COLOR="#00007F">Lib</FONT> "user32" Alias "GetWindowLongA" (<FONT COLOR="#00007F">ByVal</FONT> hwnd <FONT COLOR="#00007F">As</FONT> <FONT COLOR="#00007F">Long</FONT>, <FONT COLOR="#00007F">ByVal</FONT> nIndex <FONT COLOR="#00007F">As</FONT> <FONT COLOR="#00007F">Long</FONT>) <FONT COLOR="#00007F">As</FONT> <FONT COLOR="#00007F">Long</FONT>
<FONT COLOR="#00007F">Private</FONT> <FONT COLOR="#00007F">Declare</FONT> <FONT COLOR="#00007F">Function</FONT> SetWindowLong <FONT COLOR="#00007F">Lib</FONT> "user32" Alias "SetWindowLongA" (<FONT COLOR="#00007F">ByVal</FONT> hwnd <FONT COLOR="#00007F">As</FONT> <FONT COLOR="#00007F">Long</FONT>, <FONT COLOR="#00007F">ByVal</FONT> nIndex <FONT COLOR="#00007F">As</FONT> <FONT COLOR="#00007F">Long</FONT>, <FONT COLOR="#00007F">ByVal</FONT> dwNewLong <FONT COLOR="#00007F">As</FONT> <FONT COLOR="#00007F">Long</FONT>) <FONT COLOR="#00007F">As</FONT> <FONT COLOR="#00007F">Long</FONT>
<FONT COLOR="#00007F">Private</FONT> <FONT COLOR="#00007F">Declare</FONT> <FONT COLOR="#00007F">Function</FONT> GetSystemMenu <FONT COLOR="#00007F">Lib</FONT> "user32" (<FONT COLOR="#00007F">ByVal</FONT> hwnd <FONT COLOR="#00007F">As</FONT> <FONT COLOR="#00007F">Long</FONT>, <FONT COLOR="#00007F">ByVal</FONT> bRevert <FONT COLOR="#00007F">As</FONT> <FONT COLOR="#00007F">Long</FONT>) <FONT COLOR="#00007F">As</FONT> <FONT COLOR="#00007F">Long</FONT>
<FONT COLOR="#00007F">Private</FONT> <FONT COLOR="#00007F">Declare</FONT> <FONT COLOR="#00007F">Function</FONT> DeleteMenu <FONT COLOR="#00007F">Lib</FONT> "user32" (<FONT COLOR="#00007F">ByVal</FONT> hMenu <FONT COLOR="#00007F">As</FONT> <FONT COLOR="#00007F">Long</FONT>, <FONT COLOR="#00007F">ByVal</FONT> nPosition <FONT COLOR="#00007F">As</FONT> <FONT COLOR="#00007F">Long</FONT>, <FONT COLOR="#00007F">ByVal</FONT> wFlags <FONT COLOR="#00007F">As</FONT> <FONT COLOR="#00007F">Long</FONT>) <FONT COLOR="#00007F">As</FONT> <FONT COLOR="#00007F">Long</FONT>

<FONT COLOR="#00007F">Private</FONT> <FONT COLOR="#00007F">Const</FONT> GWL_STYLE <FONT COLOR="#00007F">As</FONT> <FONT COLOR="#00007F">Long</FONT> = (-16) <FONT COLOR="#007F00">'The offset of a window's style</FONT>
<FONT COLOR="#00007F">Private</FONT> <FONT COLOR="#00007F">Const</FONT> SC_CLOSE <FONT COLOR="#00007F">As</FONT> <FONT COLOR="#00007F">Long</FONT> = &HF060
<FONT COLOR="#00007F">Private</FONT> <FONT COLOR="#00007F">Const</FONT> WS_SYSMENU <FONT COLOR="#00007F">As</FONT> <FONT COLOR="#00007F">Long</FONT> = &H80000


<FONT COLOR="#00007F">Public</FONT> <FONT COLOR="#00007F">Sub</FONT> MinMax(sCaption <FONT COLOR="#00007F">As</FONT> <FONT COLOR="#00007F">String</FONT>, <FONT COLOR="#00007F">Optional</FONT> HideMenu <FONT COLOR="#00007F">As</FONT> <FONT COLOR="#00007F">Boolean</FONT> = <FONT COLOR="#00007F">True</FONT>)
<FONT COLOR="#00007F">Dim</FONT> hWndForm <FONT COLOR="#00007F">As</FONT> <FONT COLOR="#00007F">Long</FONT>
<FONT COLOR="#00007F">Dim</FONT> hMenu <FONT COLOR="#00007F">As</FONT> <FONT COLOR="#00007F">Long</FONT>
<FONT COLOR="#00007F">Dim</FONT> iStyle <FONT COLOR="#00007F">As</FONT> <FONT COLOR="#00007F">Long</FONT>
hWndForm = FindWindow(vbNullString, sCaption)
<FONT COLOR="#00007F">If</FONT> HideMenu <FONT COLOR="#00007F">Then</FONT>
iStyle = GetWindowLong(hWndForm, GWL_STYLE)
iStyle = iStyle And <FONT COLOR="#00007F">Not</FONT> WS_SYSMENU
SetWindowLong hWndForm, GWL_STYLE, iStyle
<FONT COLOR="#00007F">Else</FONT>
hMenu = GetSystemMenu(hWndForm, 0)
DeleteMenu hMenu, SC_CLOSE, 0&
<FONT COLOR="#00007F">End</FONT> <FONT COLOR="#00007F">If</FONT>
<FONT COLOR="#00007F">End</FONT> <FONT COLOR="#00007F">Sub</FONT></pre>
Y la llamo desde el Initialize event así:

<pre>MinMax Me.Caption</pre>
 
Upvote 0
Saludos Juan Pablo y amigos,

tu respuesta me ayudó mucho.

si alguien como me pasó a mi, no puede ver la respuesta claramente, abajo incluyo lo que escribió Juan Pablo.

Para poder leerla tuve que copiarla y pegarla a un archivo de texto y guardarlo con extensión .html (no sé porqu'e el mensaje lo veo así, talvez solo a mi me pasa) y abrirlo con el navegador de internet.

Gracias.

Respuesta ****************

La m s facil es usar el evento QueryClose as¡:
Code:
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
 If CloseMode = 0 Then Cancel = True
End Sub
As¡, la "X" no sirve. Si se quiere quitar, hay que usar unas funciones API Algo as¡:
Code:
Option Explicit
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) 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 GetSystemMenu Lib "user32" (ByVal hwnd As Long, ByVal bRevert As Long) As Long
Private Declare Function DeleteMenu Lib "user32" (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long) As Long
Private Const GWL_STYLE As Long = (-16) 'The offset of a window's style
Private Const SC_CLOSE As Long = &HF060
Private Const WS_SYSMENU As Long = &H80000

Public Sub MinMax(sCaption As String, Optional HideMenu As Boolean = True)
 Dim hWndForm As Long
 Dim hMenu As Long
 Dim iStyle As Long
 hWndForm = FindWindow(vbNullString, sCaption)
 If HideMenu Then
    iStyle = GetWindowLong(hWndForm, GWL_STYLE)
    iStyle = iStyle And Not WS_SYSMENU
    SetWindowLong hWndForm, GWL_STYLE, iStyle
 Else
    hMenu = GetSystemMenu(hWndForm, 0)
    DeleteMenu hMenu, SC_CLOSE, 0&
 End If
End Sub

Y la llamo desde el Initialize event as¡:

MinMax Me.Caption

_________________ Regards,
 
Upvote 0
Samuel,

Edité su mensaje poniendo las etiquetas de CODE para que sea más fácil leer. ¿Puede usted leerlo así?

Creo que usted está experimentando problemas con lo que puso JPG porque él usó otro Add-In de COLO para pegar ese código que se hace el text más bonito que las etiquetas sencillas.
 
Upvote 0
Hola Greg,

Si, puedo leer claramente el codigo con las etiquetas que me hiciste el favor de agregar. Lo tengo en cuenta para la siguiente vez. Gracias.
 
Upvote 0

Forum statistics

Threads
1,223,970
Messages
6,175,699
Members
452,667
Latest member
vanessavalentino83

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top