Mostrar mensaje al inicio, barra de progreso y mensaje de finalización al ejecutar MACRO

Tengo esta macro en un Módulo:

Option Explicit
Sub Combinar()
    Dim shtLista As Worksheet
    Dim strGrado As String
    Dim strNombres As String
    Dim strCedula As String
    Dim strCiudad As String
    Dim strFecha As String
    Dim filaInicial As Long
    Dim objPPT As Object
    Dim objPres As Object
    Dim objSld As Object
    Dim objShp As Object
    Rem MsgBox "Proceso INICIADOO..."
    Set shtLista = Worksheets("Listado")
    Set objPPT = CreateObject("Powerpoint.Application")
    objPPT.Visible = True
    Set objPres = objPPT.presentations.Open(ThisWorkbook.Path & "\Modelo.pptx")
    objPres.SaveAs ThisWorkbook.Path & "\Diplomas.pptx"
    filaInicial = 2
    Do While shtLista.Cells(filaInicial, 1) <> ""
        strGrado = shtLista.Cells(filaInicial, 1)
        strNombres = shtLista.Cells(filaInicial, 2)
        strCedula = shtLista.Cells(filaInicial, 3)
        strCiudad = shtLista.Cells(filaInicial, 4)
        strFecha = shtLista.Cells(filaInicial, 5)
        Set objSld = objPres.slides(1).Duplicate
        For Each objShp In objSld.Shapes
            If objShp.HasTextFrame Then
                If objShp.TextFrame.HasText Then
                    ObjShp. TextFrame. TextRange. Replace "<Grado>", strGrado
                    ObjShp. TextFrame. TextRange. Replace "<Nombres>", strNombres
                    ObjShp. TextFrame. TextRange. Replace "<Cedula>", strCedula
                    ObjShp. TextFrame. TextRange. Replace "<Ciudad>", strCiudad
                    ObjShp. TextFrame. TextRange. Replace "<Fecha>", strFecha
                End If
            End If
        Next
        filaInicial = filaInicial + 1
    Loop
    objPres.slides(1).Delete
    objPres.Save
    objPres.Close
    objPPT.Quit
    Rem MsgBox "Proceso FINALIZADO..!"
End Sub

Quiero que aparezca un Msgbox diciendo "PROCESO INICIADO" y seguidamente, se muestre una barra de progreso así:

Private Sub UserForm_Activate()
Dim Conteo As Long
Dim nFilas As Long
Dim nColumnas As Long
Dim f As Long
Dim c As Long
Dim Porcentaje As Double

Cells.Clear
Conteo = 1
nFilas = 5000
nColumnas = 100
For f = 1 To nFilas
For c = 1 To nColumnas
Cells(f, c) = Conteo
Conteo = Conteo + 1
Next c
Porcentaje = Conteo / (nFilas * nColumnas)
Me.Caption = Format(Porcentaje, "0%" & " Ejecutado...")
Me.Label1.Width = Porcentaje * Me.Frame1.Width
DoEvents
Next f
Unload Me
End Sub

Y finalmente, al terminar, que active Microsoft Excel, lo traiga al frente y muestre un MSGBOX diciendo: "PROCESO FINALIZADO"

Respuesta
2

Para el primer mensaje puedes usar esto:

Sub ActivaPrimerCorte()
    'Para primer herramienta
resultado = MsgBox("¿Desea iniciar la primer actualización de Cargas?", vbYesNo, "Monitor de Embarques")
'
    If resultado = vbYes Then
            Msbox "Proceso Iniciado"
            Unload PrimerCorte
                Load Actualizando
            Actualizando.Show
        Else
             MsgBox ("Se ha omitido la la primer actualización del día")
        End
    End If
'
End Sub

Para que el formulario progrese debes hacer tu formulario como activate, te dejo un ejemplo de cómo hacerlo en esta liga que antes respondí: Crear barra de progreso para macros.

Para que al finalizar aparezca otro mensaje (viene en el link de arriba):

MsgBox "Ha terminado el proceso de actualización de Semáforo", vbOKOnly, "Monitor de Embarques"

Para tu última línea de código.

1 respuesta más de otro experto

Respuesta
1

Realiza lo siguiente:

1. Crea un userform

2. En el userform crea un control Frame1, con un ancho (Width) de 200

3. Dentro del Frame1 agrega un Label1:

4. Pon todo el siguiente código dentro del userform:

Option Explicit
'
Sub Combinar_New()
  Dim shtLista As Worksheet
  Dim strGrado As String, strNombres As String, strCedula As String
  Dim strCiudad As String, strFecha As String
  Dim filaInicial As Long, filaFinal As Long
  Dim objPPT As Object, objPres As Object
  Dim objSld As Object, objShp As Object
  Dim Porcentaje As Double
  '
  CreateObject("WScript.Shell").PopUp "Proceso INICIADO...", 1, "COMBINAR"
  Set shtLista = Worksheets("Listado")
  '
  Set objPPT = CreateObject("Powerpoint.Application")
  objPPT.Visible = True
  Set objPres = objPPT.presentations.Open(ThisWorkbook.Path & "\Modelo.pptx")
  objPres.SaveAs ThisWorkbook.Path & "\Diplomas.pptx"
  '
  filaInicial = 2
  filaFinal = shtLista.Range("A" & Rows.Count).End(3).Row
  '
  Do While shtLista.Cells(filaInicial, 1) <> ""
    Porcentaje = filaInicial / filaFinal
    Me.Caption = Format(Porcentaje, "0%" & " Ejecutado...")
    Me.Label1.Width = Porcentaje * Me.Frame1.Width
    DoEvents
    '
    strGrado = shtLista.Cells(filaInicial, 1)
    strNombres = shtLista.Cells(filaInicial, 2)
    strCedula = shtLista.Cells(filaInicial, 3)
    strCiudad = shtLista.Cells(filaInicial, 4)
    strFecha = shtLista.Cells(filaInicial, 5)
    Set objSld = objPres.slides(1).Duplicate
    For Each objShp In objSld.Shapes
      If objShp.HasTextFrame Then
        If objShp.TextFrame.HasText Then
          ObjShp. TextFrame. TextRange. Replace "<Grado>", strGrado
          ObjShp. TextFrame. TextRange. Replace "<Nombres>", strNombres
          ObjShp. TextFrame. TextRange. Replace "<Cedula>", strCedula
          ObjShp. TextFrame. TextRange. Replace "<Ciudad>", strCiudad
          ObjShp. TextFrame. TextRange. Replace "<Fecha>", strFecha
        End If
      End If
    Next
    filaInicial = filaInicial + 1
  Loop
  objPres.slides(1).Delete
  objPres.Save
  objPres.Close
  objPPT.Quit
  MsgBox "Proceso FINALIZADO..!"
End Sub
'
Private Sub UserForm_Activate()
  Call Combinar_New
End Sub

5. Ejecuta el userform, ya no ejecutes la macro desde el módulo.

6. Cuando empieza la ejecución del userform aparece el mensaje: "Proceso INICIADO", éste se desaparece automáticamente después de un segundo, o puedes presionar el botón "Aceptar".

7. La barra de progreso se empezará a actualizar. Depende del número de filas que tienes en la hoja "Listado".

8. Al final la ejecución aparece el mensaje: "Proceso FINALIZADO..!"


..

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas