Ocultando CommandButtons Indexando

joelcg

New Member
Joined
Dec 29, 2004
Messages
5
?Como hago para lograr que VBA me oculte los 5 siguientes CommandButtons al valor de la variable que le doy?

Ejemplo

Sub Oculta()

Dim a As Integer

a = 1

For a = 1 To 5

UserForm1.CommandButton(a).Visible = False
a = a + 1

Next a

UserForm1.Show

End Sub
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Joel,

En casos así, es mejor utilizar la propiedad Tag de los controles. El ejemplo abajo se usa Tag para guardar una sola propiedad "custom". Con usar un ClassModule uno puede guardar varios, pero el class module que tengo fue comprado y no lo encuentro gratis en el internet asi que no siento comodo copiándolo aquí. Sin embargo, aquí está un ejemplo usando Tag...

<font face=Courier New><SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> UserForm_Initialize()

    <SPAN style="color:#00007F">Dim</SPAN> ctl <SPAN style="color:#00007F">As</SPAN> MSForms.Control
    
    For <SPAN style="color:#00007F">Each</SPAN> ctl <SPAN style="color:#00007F">In</SPAN> Me.Controls
        <SPAN style="color:#00007F">If</SPAN> ctl.Tag = "Escóndeme" <SPAN style="color:#00007F">Then</SPAN> ctl.Visible = <SPAN style="color:#00007F">False</SPAN>
    <SPAN style="color:#00007F">Next</SPAN> ctl
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN>
</FONT>

Usted cambia el valor de los «Tags» de los controles a mano por medio de la "properties window". Esta estrategia es más fuerte porque si uno agrega o suprime controles, el programa no falla. Espero que le ayude.

Saludos,
 
Upvote 0

Forum statistics

Threads
1,223,952
Messages
6,175,589
Members
452,653
Latest member
craigje92

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