Vous êtes sur la page 1sur 4

Conceptos bsicos Clase 1 Programacin del Excel con VBA

Sub y funcion
Sub suma()
Sum = 4 + 6
MsgBox "LA suma es: " & Sum
End Sub
Function MiPromedio(num1, num2)
MiPromedio = (num1 + num2) / 2
End Function
Referencia a Objetos
Referencia a la Hoja Uno del Libro Uno
Workbooks("Libro1").Worksheets("Hoja1")
Referencia al Rango o Celda A1 de la Hoja Uno del Libro Uno
Workbooks("Libro1").Worksheets("Hoja1").Range("A1")
Propiedades de los Objetos y Ver el Valor
Sub CambiaValoresDeCelda()
Worksheets("Hoja1").Range("A1").Value = 12345
End Sub
Sub LecturaDeValor()
MsgBox Worksheets("Hoja1").Range("A1").Value
End Sub
Metodos y Argumentos
Sub BorrarValoresYFormato()
Worksheets("Clase 1").Range("A1:C3").Clear
End Sub
Sub CopiarAOtroLugar()
Range("D1").Copy Range("E1")
End Sub
Sub OtroModoDeCopiarAOtroLugar()
Range("D2").Copy Destination:=Range("E2")
End Sub

El objeto Comment Clase 2 Programacin del Excel con VBA


Ver Comentarios

Option Explicit
Sub TextoPrimerComentario()
MsgBox Worksheets("Hoja2").Comments(1).Text
End Sub
Sub ContarComentarios()
MsgBox ActiveSheet.Comments.Count
End Sub
Sub CeldaDelComentario()
MsgBox Worksheets("Hoja2").Comments(1).Parent.Address
End Sub
Sub MostrarTodos()
Dim comentario As Comment
For Each comentario In ActiveSheet.Comments
MsgBox comentario.Text
Next comentario
End Sub
Sub ContenidoComentarioCelda()
MsgBox Worksheets("Hoja2").Range("C2").Comment.Text
End Sub
Cambiar las propiedades de los comentarios (Objeto dentro de un
Objeto Comment)
Sub CambiarColorFondo()
Worksheets("Hoja2").Comments(1).Shape.Fill.ForeColor.RGB =
RGB(0, 255, 0)
End Sub
Sub CambiarColorTexto()
Worksheets("Hoja2").Comments(2).Shape.TextFrame.Characters.Fo
nt.Color = RGB(0, 0, 255)
End Sub
Sub ObtenerComentario()
MsgBox Worksheets("Hoja2").Range("J5").Comment
End Sub
Sub InsertarCometario()
If Worksheets("Hoja2").Range("J5").Comment Is Nothing Then
Worksheets("Hoja2").Range("J5").AddComment "Nuevo
comentario."
Else
MsgBox Worksheets("Hoja2").Range("J5").Comment.Text

End If
End Sub
El objeto Range Clase 3 Programacin del Excel con VBA
Range
Sub a()
Application.Workbooks("Clases").Worksheets("Hoja3").Range("A1")
.Value = 5
End Sub
Sub b()
Application.ActiveWorkbook.ActiveSheet.Range("A3:A10").Value
=8
End Sub
Sub c()
Range("C1") = "% IVA"
Range("Valores") = "16%"
End Sub
Sub d()
Range("D3", "E10") = 1.28
End Sub
Sub e()
Range("D1:E10 B2:F2") = "Cabecera"
Range("F3,F5,F7,F9") = 250
End Sub
Sub f()
ActiveSheet.Range("F2").Range("B1:D1") = "Titulo"
Range("G2:I10").Range("A2:B9") = 63
End Sub
Cell
Sub g()
ActiveSheet.Cells(2, 10).Value = "Otro titulo"
Cells(3, 10) = 829
Range("J2").Cells(3, 1) = 615
Range(Cells(5, 10), Cells(10, 10)) = 292
End Sub
Sub h()
ActiveSheet.Cells(16395) = "New title"
Range("k3:L10").Cells(1) = 456
End Sub

Sub i()
Range("A1:E9").Cells.ClearContents
MsgBox "Borramos tan solo un rango de celdas."
ActiveSheet.Cells.ClearContents
MsgBox "Ahoraborramos todas las celdas de la hoja activa"
End Sub
Offset
Sub j()
Range("C2").Offset(3, 2).Value = 15
ActiveCell.Offset(0, 0) = 30
Range("E5").Offset(-3, -2) = 45
End Sub
Elementos del lenguaje VBA Clase 4 Programacin del Excel con
VBA

Vous aimerez peut-être aussi