Download - Codigo VBA Excel
-
8/17/2019 Codigo VBA Excel
1/4
Codigo Combobox
Private Sub ComboBox1_Enter()
ComboBox1.AddItem "Daniel"
ComboBox1.AddItem "Emanuel"
End Sub
Private Sub Userorm_Initiali!e()
ComboBox1.ist # Arra$("%ed"& "'reen"& "ello"& "Blue")
End Sub
Codigo para buscar
Private Sub Bus*ar_Cli*+()
Dim ,ila As Inte-er Dim Bus*ar As Strin-
Dim Dato As Strin-
,ila #
Do /0ile ,ila 2 34
,ila # ,ila 5 1
Dato # 6extBox1.7alue
Bus*ar # %an-e("a" 8 ,ila).7alue
I, Dato # Bus*ar 60en
6extBox3 # %an-e("A" 8 ,ila).7alue
6extBox9 # %an-e("B" 8 ,ila).7alue
6extBox: # %an-e("C" 8 ,ila).7alue
6extBox4 # %an-e("D" 8 ,ila).7alue
6extBox; # %an-e("E" 8 ,ila).7alue
6extBox< # %an-e("" 8 ,ila).7alue
Exit Do
End I,
oo=End Sub
-
8/17/2019 Codigo VBA Excel
2/4
-
8/17/2019 Codigo VBA Excel
3/4
Arrays con la funcion Lbound y Ubound
Private Sub CommandButton1_Cli*+()
Dim ombre(3) As Strin-
Dim x As Inte-er
ombre() # "Daniel"
ombre(1) # "Emanuel"
ombre(3) # "arit!abel"
or x # Bound(ombre) 6o UBound(ombre)
s-Box ombre(x)
ext x
End Sub
Asignacion de celdas de Excel a un Array
Private Sub CommandButton1_Cli*+()
Dim ombre(3) As Strin-
Dim Parente!*o(3) As Strin-
Dim Edad(3) As Strin-
Dim x As Inte-er
Dim ! As Inte-er
or ! # 1 6o 9
ombre(! 1) # %an-e("A" 8 !).7alue
Parente!*o(! 1) # %an-e("B" 8 !).7alue
Edad(! 1) # %an-e("*" 8 !).7alue
ext !
or x # Bound(ombre) 6o UBound(ombre)
s-Box ombre(x) 8 " " 8 Parente!*o(x) 8 " " 8 Edad(x)
ext x
End Sub
Ocultar libro de Excel y ejecutar macro (Se debe insertar un modulo $ =oner el *odi-o)
Sub auto_o=en()
A==li*ation.7isible # alse
End sub
Ejecutar macro al abrir un libro (Se debe insertar un modulo $ =oner el *odi-o)
Sub auto_o=en()
User,orm.s0o
End sub
-
8/17/2019 Codigo VBA Excel
4/4
Codigo para deshabilitar boton de cerrar en userform
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As _ Integer) I CloseMode ! vbFormControlMenu "#en Cancel ! "rue $nd Sub
Codigo para agregar botones de minimizar y maximizar
>=tion Ex=li*it
Private De*lare un*tion ind/indo ib "user93" Alias "ind/indoA" (B$7al l=Classame As Strin-&
B$7al l=/indoame As Strin-) As on-
Private De*lare un*tion Set/indoon- ib "user93" Alias "Set/indoon-A" (B$7al 0/nd As on-&
B$7al nIndex As on-& B$7al deon- As on-) As on-
Private De*lare un*tion 'et/indoon- ib "user93" Alias "'et/indoon-A" (B$7al 0/nd As on-&
B$7al nIndex As on-) As on-
Private Const /S_IIIEB>F As on- # 8G3
Private Const /S_AFIIEB>F As on- # 8G1
Private Const '/_S6E As on- # (1;)
Private Sub Userorm_Initiali!e()
Dim ln-$Gandle As on-& ln-CurrentSt$le As on-& ln-eSt$le As on-
H>btenemos el "Gandle" del User,orm
ln-$Gandle # ind/indo("6GUDE%D%AE"& e.Ca=tion)
H>btenemos el estilo a*tual del Userorm
ln-CurrentSt$le # 'et/indoon-(ln-$Gandle& '/_S6E)
HCreamos un nuevo estilo de titulo *on los botones deseados
ln-eSt$le # ln-CurrentSt$le >r /S_IIIEB>F >r /S_AFIIEB>F
HA=li*amos las nuevas =ro=iedades al Userorm
Set/indoon- ln-$Gandle& '/_S6E& ln-eSt$le
End Sub