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!
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"
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
''''''''''''''''''''''''''''''''''''' 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