Documentos de Académico
Documentos de Profesional
Documentos de Cultura
Un ejemplo de una macro VBA de como crear una barra de progreso (progress bar) para
incluir en nuestras aplicaciones y plantillas Excel.
El código
Option Explicit
Sub BarraDeProgreso()
Dim R As Integer
Dim MT As Double
For R = 1 To 180
MT = Timer
Do
Loop While Timer - MT < 0.05
Application.StatusBar = "Progress: " & R & " de 180: " & _
Format(R / 180, "Percent") & " --- " & "Cumplimiento"
DoEvents
Next R
Application.StatusBar = False
End Sub
Ejemplos de macros
En esta página iremos insertando macros y códigos que pueden servirle de ayuda.
End If
End Sub
Sub guardar_archivo()
Dim stArchivo
stArchivo = Application.GetOpenFilename(“Hoja de Excel , *.xls*”, _
, “Seleccione archivo “)
End Sub
Sub guardar_archivo_otro()
‘con esta macro guardamos el archivo con la fecha y hora actual y formato csv
Dim nombre, nombrearch, hoja, ruta
nombre = Format(Now, “dd-mm-yy hh.mm.ss”)
ruta = ActiveWorkbook.Path
nombrearch = ActiveWorkbook.Name
hoja = ActiveSheet.Name
ActiveWorkbook.SaveAs Filename:=ruta & “\” & hoja & nombre & “.csv”,
FileFormat:=xlCSV
ActiveSheet.SaveAs ruta & “\” & nombrearch & nombre & “.xlsm”
End Sub
Si queremos que se quiera copiar los rangos de la hoja activa de una hoja a otra
ejecutariamos la macro siguiente:
Option Explicit
Dim f, c
Public Sub CopiarRango()
ActiveCell.CurrentRegion.Select
f = ActiveCell.Row
c = ActiveCell.Column
Selection.Copy
Sheets(“Hoja2″).Activate
Cells(f, c).Activate
ActiveSheet.Paste
End Sub
ActiveWorkbook.Close
ActiveWorkbook.Close Savechanges:=True
ActiveWorkbook.Close(True)
ActiveWorkbook.Close(False)
ActiveWorkbook.Close Savechanges:=False
Sub ultima_hoja()
Sheets(Sheets.Count).Select
End Sub
Sub primera_hoja()
Sheets(1).Select
End Sub
Sub CopiaColumnas()
Dim mirango As Range
Dim col As Range
Dim NuevaHoja As Worksheet
Dim i As Integer
Worksheets.Add
i=0
For Each col In mirango.Columns
col.Copy ActiveSheet.Range(“A1″).Offset(, i)
i=i+1
Next col
End Sub
Sub ultimafila()
‘variable donde almacenamos el número de fila
Dim ultima As Long
End Sub
intLastRow = Columns(“A:A”).Range(“A65536″).End(xlUp).Row
For r = intLastRow To 1 Step -1
If Application.CountA(Rows(r)) = 0 Then Rows(r).Delete
Next r
Do
Set rngString = Cells.Find(“Aglis”, MatchCase:=False, _
LookAt:=xlPart, LookIn:=xlValues)
If Not rngString Is Nothing Then
rngString.EntireRow.Delete
End If
Loop Until rngString Is Nothing