08-MacrosVBAExcelAvanzado-EAA

download 08-MacrosVBAExcelAvanzado-EAA

of 15

Transcript of 08-MacrosVBAExcelAvanzado-EAA

  • 7/29/2019 08-MacrosVBAExcelAvanzado-EAA

    1/15

    Excel Avanzado con VBA 08

    Ing. Enrique Alfaro

  • 7/29/2019 08-MacrosVBAExcelAvanzado-EAA

    2/15

    Agregando Controles

    Hay 3 tipos: Controles de Formulario (Form Controls) Controles ActiveX (ActiveX Controls)

    Controles de Formulario de usuario(UserForm Controls)

    17/02/2013Ing. Enrique Alfaro

  • 7/29/2019 08-MacrosVBAExcelAvanzado-EAA

    3/15

    17/02/2013Ing. Enrique Alfaro

    Controles de Formulario

  • 7/29/2019 08-MacrosVBAExcelAvanzado-EAA

    4/15

    17/02/2013Ing. Enrique Alfaro

    Controles ActiveX

  • 7/29/2019 08-MacrosVBAExcelAvanzado-EAA

    5/15

    Controles ActiveX (1/2)

    Private Sub CommandButton1_Click()If ComboBox1.ListCount = 0 ThenRange("E5").SelectRange(Selection, Selection.End(xlDown)).Select

    For i = 1 To Selection.CountComboBox1.AddItem (ActiveCell.Cells(i,

    1).Value)Next

    ElseMsgBox "ya se agregaron los datos"

    End If End Sub

    17/02/2013Ing. Enrique Alfaro

  • 7/29/2019 08-MacrosVBAExcelAvanzado-EAA

    6/15

    Control ActiveX (2/2)

    Private Sub ComboBox1_Change()Range("e5:g11").Name = "rango"Range("C4").Value = ComboBox1.ValueRange("c5").Value = "=VLookup(c4, rango, 2,

    False)"Range("c6").Value = "=VLookup(c4, rango, 3,

    False)"End Sub

    Private CommandButton2_Click()ComboBox1.ClearRange("C4:C6").ClearContents

    End Sub

    17/02/2013Ing. Enrique Alfaro

  • 7/29/2019 08-MacrosVBAExcelAvanzado-EAA

    7/15

    Control ActiveX ejemplo2

    17/02/2013Ing. Enrique Alfaro

  • 7/29/2019 08-MacrosVBAExcelAvanzado-EAA

    8/15

    Control ActiveX ejemplo2

    17/02/2013Ing. Enrique Alfaro

  • 7/29/2019 08-MacrosVBAExcelAvanzado-EAA

    9/15

    Control ActiveX ejemplo2

    17/02/2013Ing. Enrique Alfaro

    17/02/2013I E i Alf

  • 7/29/2019 08-MacrosVBAExcelAvanzado-EAA

    10/15

    Control ActiveX ejemplo2

    17/02/2013Ing. Enrique Alfaro

    17/02/2013I E i Alf

  • 7/29/2019 08-MacrosVBAExcelAvanzado-EAA

    11/15

    17/02/2013Ing. Enrique Alfaro

    UserForm Controles

    17/02/2013I g E iq Alf

  • 7/29/2019 08-MacrosVBAExcelAvanzado-EAA

    12/15

    UserForms Controles (1/4)

    Private Sub CommandButton1_Click() vacio = FalseIf TextBox1.Text = "" Or TextBox2.Text = "" ThenIf TextBox1.Text = "" Then

    MsgBox "Ud. no ingreso el detalle"TextBox1.SetFocusvacio = True

    ElseMsgBox "Ud. no ingreso la cantidad"TextBox2.SetFocusvacio = True

    End If End if

    17/02/2013Ing. Enrique Alfaro

    17/02/2013Ing Enrique Alfaro

  • 7/29/2019 08-MacrosVBAExcelAvanzado-EAA

    13/15

    UserForms Controles (2/4)rpta = ""If vacio = False Then

    rpta = MsgBox("Seguro de guardar?", vbQuestion + vbYesNo,"CONFIRMAR")

    If rpta = vbYes Then

    detalle = TextBox1.Textcantidad = TextBox2.TextRange("B1").SelectSelection.End(xlDown).SelectSelection.AutoFill Destination:=ActiveCell.Range("A1:A2")ActiveCell.Offset(1, 0).SelectActiveCell.Offset(0, 1).Value = detalleActiveCell.Offset(0, 2).Value = cantidad

    End If End If End Sub

    17/02/2013Ing. Enrique Alfaro

    17/02/2013Ing Enrique Alfaro

  • 7/29/2019 08-MacrosVBAExcelAvanzado-EAA

    14/15

    UserForms Controles (3/4)

    Private Sub CommandButton2_Click()TextBox1.Text = ""TextBox2.Text = ""TextBox1.SetFocusvacio = False

    End Sub

    Private Sub CommandButton3_Click()Application.ScreenUpdating = FalseUnload Me

    End Sub

    17/02/2013Ing. Enrique Alfaro

    17/02/2013Ing Enrique Alfaro

  • 7/29/2019 08-MacrosVBAExcelAvanzado-EAA

    15/15

    UserForms Controles (4/4)

    El procedimiento siguiente se utilizar para Llamar a la caja dedilogo UserForm1 desde un botn de comando ActiveXinsertado en la hoja de clculo:

    Private Sub CommandButton1_Click()Application.ScreenUpdating = TrueUserForm1.Show

    End Sub

    17/02/2013Ing. Enrique Alfaro