Está en la página 1de 9

MACROS EN EXCEL CON VB

Clase Fecha – Fecha – Tema


# Grupo 1 Grupo 2
1 19-ene-14 1-feb-14 Introducción general - Editor de Visual Basic - Macros
2 8-feb-14 2-feb-14 Normalización- desarrollo- Lógica - Algoritmos
3 9-feb-14 22-feb-14 Lenguaje 1 - Proyecto
4 1-mar-14 23-feb-14 Lenguaje 2 - Proyecto
5 2-mar-14 15-mar-14 Lenguaje 3 - Proyecto
6 22-mar-14 16-mar-14 Lenguaje 4 - Proyecto
7 23-mar-14 5-abr-14 Taller 3
8 12-abr-14 6-abr-14 Taller 4
9 13-abr-14 26-abr-14 Taller 5
10 3-mayo-14 27-abr-14 Taller 6
TALLER

1. Se tienen las coordenadas en metros (x,y) de un lote cualquiera (# de


vértices variable), escriba una macro que calcule el área.
Ejemplos de Código

1. Escuchar música mientras se ejecuta una macro.

Private Sub WindowsMediaPlayer1_Click(ByVal nButton As Integer, ByVal nShiftState As


Integer, ByVal fX As Long, ByVal fY As Long)
WindowsMediaPlayer1.URL = "C:\Users\Public\Music\Sample Music\Kalimba.mp3"
WindowsMediaPlayer1.Controls.play
End Sub
Ejemplos de Código
2. Enviar un correo electrónico por Outlook.
Sub Send_Msg()
Dim objOL As New Outlook.Application
Dim objMail As MailItem

Set objOL = New Outlook.Application


Set objMail = objOL.CreateItem(olMailItem)

With objMail
.To = "srosales@drummondltd.com"
.Subject = "Automated Mail Response"
.Body = "This is an automated message from Excel. " & _
“El costo total del artículo que requiere es: " & _
Format(Range("A1").Value, "$ #,###.#0") & "."
.Display
.Send
End With

Set objMail = Nothing


Set objOL = Nothing
End Sub
Ejemplos de Código
3. Escribir un documento en Word.
Sub Open_MSWord()
On Error GoTo errorHandler
Dim wdApp As Word.Application
Dim myDoc As Word.Document
Dim mywdRange As Word.Range
Set wdApp = New Word.Application

With wdApp
.Visible = True
.WindowState = wdWindowStateMaximize
End With

Set myDoc = wdApp.Documents.Add


Ejemplos de Código
3. Escribir un documento en Word.

With wdApp
.Selection.TypeText Text:="Texto de Prueba"
.Selection.TypeParagraph
.Selection.TypeText Text:="Use TypeParagraph para adicionar un espacio"
.Selection.TypeParagraph
.Selection.TypeText Text:=Range("A2") & " " & Range("C2")
End With

Rem guardar
wdApp.ActiveDocument.SaveAs Filename:="C:\Users\srosales\Desktop\Hola.doc"

errorHandler:

Set wdApp = Nothing


Set myDoc = Nothing
End Sub
Ejemplos de Código
4. Sacar información de otra hoja de cálculo .xls
Sub LeerValores()
Dim Val1 As Double, Val2 As Double
Dim DataWorkbook As Workbook

Set DataWorkbook = Workbooks.Open("C:\Users\srosales\Desktop\Curso de Macros en Excel\Clase


10 Taller 6\Ej4 Datos")

Val1 = Sheets("Sheet1").Cells(1, 1)
Val2 = Sheets("Sheet1").Cells(1, 2)

DataWorkbook.Close

Call UsarValores(Val1, Val2)

End Sub


Ejemplos de Código
4. Sacar información de otra hoja de cálculo .xls

Sub UsarValores(A, B)

ActiveWorkbook.Sheets("Sheet1").Cells(2, 1) = A * 10
ActiveWorkbook.Sheets("Sheet1").Cells(2, 2) = B * 10

End Sub

También podría gustarte