Para DANTE AMOR agregar a una macro una nueva instrucción

Hola DAM

Quería comentarte que tu me ayudaste con esta macro que te escribo a continuación:

Sub CrearACtxt()
'Por.Dante Amor
    Application.DisplayAlerts = False
    Application.ScreenUpdating = False
    Set L1 = ThisWorkbook
    Set H1 = L1.Sheets("AC")
    Set l2 = Workbooks.Add
    Set h2 = l2.ActiveSheet
    '
    u = H1.Range("B" & Rows.Count).End(xlUp).Row
    H1.Range("A2:M" & u).Copy h2.Range("A1")
    h2.[G1] = "10"
    h2.[H1] = "13"
    h2.Range("G1:H1").AutoFill Destination:=Range("G1:H" & u - 1)
    h2.Columns("I:K").Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
    h2.Columns("F:F").Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
    '
    ruta = L1.Path & "\"
    nombre = "AC000"
    l2.SaveAs Filename:=ruta & nombre & ".txt", FileFormat:=xlCSV
    '
    l2.Close
    MsgBox "Archivo TXT creado", vbInformation
End Sub

Pero quisiera que me ayudaras a agregarle 2 aspectos importantes que me hicieron falta.

El primero es que al momento de ejecutar la macro, me solicite a través de un msgbox "Favor introducir el numero de Factura a Generar" allí yo colocaría un número.

Al colocar ese numero y dar click en siguiente o continuar, ese valor que ingresé se debe registrar en la celda "A2" y luego si ejecutar el resto de la macro que tenemos.

Pero algo adicional y es que cuando vaya a grabar el archivo TXT me gustaría que quedara con el nombre de "AC000" más el numero de la factura ejemplo que el numero de la factura fuera 321 entonces el archivo debería quedar con el nombre "AC000321.txt"

Gracias, espero me halla hecho entender.

1 Respuesta

Respuesta
1

Te anexo la macro con los cambios

Sub CrearACtxt()
'Por.Dante Amor
    Application.DisplayAlerts = False
    Application.ScreenUpdating = False
    Set l1 = ThisWorkbook
    Set h1 = l1.Sheets("AC")
    Set l2 = Workbooks.Add
    Set h2 = l2.ActiveSheet
    '
    nfact = InputBox("Favor introducir el numero de Factura a Generar: ")
    If nfact = "" Then Exit Sub
    h1.[A2] = nfact
    '
    u = h1.Range("B" & Rows.Count).End(xlUp).Row
    h1.Range("A2:M" & u).Copy h2.Range("A1")
    h2.[G1] = "10"
    h2.[h1] = "13"
    h2.Range("G1:H1").AutoFill Destination:=Range("G1:H" & u - 1)
    h2.Columns("I:K").Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
    h2.Columns("F:F").Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
    '
    ruta = l1.Path & "\"
    nombre = "AC000" & nfact
    l2.SaveAs Filename:=ruta & nombre & ".txt", FileFormat:=xlCSV
    '
    l2.Close
    MsgBox "Archivo TXT creado", vbInformation
End Sub

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas