Cursos Clases en vivo Foro Ranking estudiantes Blog
Iniciar sesión Inscribirme

Es necesario estar inscrito para dejar tu duda, comentario y/o respuesta

Todo

Sin respuesta

Solo preguntas

Excel

Power BI

Power Query

Power Pivot

DAX

Macros VBA

SQL

Comentarios en clases

Necesito que la MACRO ME PREGUNTE SI DESEO O NO IMPRIMIR

Publicado por DanicelDugarte hace 1 mes

Buenos días profesora Julia, ese es el código que escribí (el mismo que está en Excel e Info)  y si , me faltó INDICAR QUE ESE ES EL QUE TENGO, PERO QUE NO ME REALIZA LA ACCIÓN QUE ESTOY BUSCANDO, es decir, necesito lograr que cuando vaya a REGISTRAR la factura me pregunte ¿DESEA IMPRIMIRLA? de manera que si es NO solamente me guarde en PDF.
Por favor me podría ayudar a corregir esta situación.
Gracias!

MACRO QUE TENGO PERO NECESITO QUE INDIQUE SI DESEO O NO IMPRIMIR
Votos 0
Respuestas
3
Respuestas
JuliaBravo490

respondió hace hace 1 mes:

Hola, Danicel.

Puedes probar el siguiente código y adaptarlo como consideres necesario:

Sub RegistrarFactura()

    Dim Ruta As String
    Dim NumFactura As String
    Dim respuesta As VbMsgBoxResult

    ' Asignar número de factura (puedes adaptarlo a tu lógica)
    NumFactura = Range("A1").Value ' Suponiendo que el número está en la celda A1

    ' Mostrar el diálogo para seleccionar carpeta
    With Application.FileDialog(msoFileDialogFolderPicker)
        .InitialFileName = Application.DefaultFilePath & "\"
        .Title = "ATENCIÓN - Seleccionar carpeta"
        If .Show <> -1 Then Exit Sub ' Si el usuario cancela
        Ruta = .SelectedItems(1)
    End With

    ' Preguntar si se desea imprimir la factura
    respuesta = MsgBox("¿DESEA IMPRIMIRLA?", vbYesNo + vbQuestion, "DEZTACA")

    If respuesta = vbYes Then
        ActiveSheet.PrintOut
    End If

    MsgBox "Guardando en PDF Factura '" & NumFactura & "'. Presione Aceptar para continuar...", _
           vbInformation, "DEZTACA"

    ' Guardar como PDF
    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
        Filename:=Ruta & "\" & "Factura-" & NumFactura & ".pdf", _
        Quality:=xlQualityStandard, IncludeDocProperties:=True, _
        IgnorePrintAreas:=False, OpenAfterPublish:=True

    MsgBox "Factura registrada correctamente.", vbInformation, "DEZTACA"

End Sub



Me dejas saber si te sirve.

Saludos,
Julia
Votos 2
DanicelDugarte

respondió hace hace 1 mes:

Buenas noches profesora, la verdad que súper agradecida por su ayuda, me funcionó de maravilla. Bendiciones.
Registro_Ventas.jpg 78.52 KB
Ventas.jpg 91.1 KB
Estas son las imágenes se la presento con filas y columnas para que puedan entender el código macro. 
Votos 0
DanicelDugarte

respondió hace hace 1 mes:

Código Macro:

Option Explicit
Sub Guardarventas()
Dim NombreHoja As String
Dim HojaDestino As Range
Dim NuevaFila As Integer
Dim FilasFactura As Integer
Dim i As Integer
Dim j As Integer
Dim NumFactura As String
Dim Ruta As String
Dim respuesta As VbMsgBoxResult


NombreHoja = "Ventas"
FilasFactura = Application.WorksheetFunction.CountA(Range("Ventas_1[Cód. Prod]"))
NumFactura = ThisWorkbook.Sheets("RegVentas").Range("C7").Value

'''''''''''''''''''''''''''''''''''''
If FilasFactura = 0 Or Range("valCliente").Value = "" Then _
MsgBox "Debes elegir un ciente e ingresar un código", vbExclamation, "ATENCIÓN": Exit Sub

' Preguntar si se desea imprimir la factura
    respuesta = MsgBox("¿DESEA IMPRIMIRLA?", vbYesNo + vbQuestion, "DEZTACA")

    If respuesta = vbYes Then
        ActiveSheet.PrintOut
    End If
    
'Propiedad FileDialog
        With Application.FileDialog(msoFileDialogFolderPicker)
            .InitialFileName = Application.DefaultFilePath & " \ "
            .Title = "ATENCIÓN - Seleccionar carpeta"
            .Show
            If .SelectedItems.Count = 0 Then
            Else
                Ruta = .SelectedItems(1)

                    MsgBox "Guardando en PDF Factura '" & NumFactura & "'. Presione Aceptar para continuar...", _
                    vbInformation, "DEZTACA"
                    
                    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
                    Ruta & "\" & "Factura-" & NumFactura & ".pdf", Quality:=xlQualityStandard, _
                    IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=True
            End If
        End With

'''''''''''''''''''''''''''''''''''''

 
With ThisWorkbook.Sheets(NombreHoja)

    For i = 1 To FilasFactura
        Set HojaDestino = ThisWorkbook.Sheets(NombreHoja).Range("A1").CurrentRegion
        NuevaFila = HojaDestino.Rows.Count + 1
        .Cells(NuevaFila, 1).Value = Range("Date").Value
        .Cells(NuevaFila, 2).Value = NumFactura
        .Cells(NuevaFila, 3).Value = Range("valCliente").Value
        .Cells(NuevaFila, 4).Value = Range("RIFCliente").Value
        .Cells(NuevaFila, 12).Value = Range("TDOC").Value
        .Cells(NuevaFila, 13).Value = Range("DivisaV").Value
        .Cells(NuevaFila, 14).Value = Range("Fpago").Value
        
            For j = 1 To 7
                .Cells(NuevaFila, j + 4).Value = ThisWorkbook.Sheets("RegVentas").Cells(15 + i, 2 + j)
            Next j
    Next i

End With
    Range("C8:C10").Select
    Selection.ClearContents
    Range("Ventas_1[Cód. Prod]").Select
    Selection.ClearContents
    Range("Ventas_1[REF. BUSCAR]").Select
    Selection.ClearContents
    Range("Ventas_1[Cant.]").Select
    Selection.ClearContents
    Range("g41").Select
    Selection.ClearContents
MsgBox "Registro Exitoso"

End Sub

Votos 1
Es necesario estar inscrito para dejar tu duda, comentario y/o respuesta
Cursos Foro Clase en vivo Validar certificado Iniciar sesión Inscribirme Términos y condiciones
Facebook Instagram Linkedin
Deztaca Experience
© 2025 © Deztaca. Todos los derechos reservados.