Macro que Guardar archivo en pdf, y ahora que sea en xlsx
A los miembros de este foro, quisiera ver la posibilidad de mejorar la macro, esta macro me permite grabar en PDF ahora lo que me piden es grabar .xlsx, bajo el mismo detalle:
Dim valor As String: Dim NOMBRE As String
Private Sub CommandButton1_Click()
Sheets("boleta").Select
End
End SubPrivate Sub ListBox1_Click()
'Act.Por.Dante Amor
LIMPIA
Set x = Worksheets("BOLETA")
Set y = Worksheets("TRABAJADOR")
valor = ListBox1.Value
numero = ListBox1.ListIndex + 1
Set Z = x.Range("b:b")
With Z
Set busca = .Find(valor, LookIn:=xlValues)
End With
r = busca.Address
ri = Range(r).Offset(-10, -1).Address
'rf = Range(ri & ":m" & numero * 62).Address
rf = Range(ri & ":o" & numero * 67).Address
PREGUNTA = MsgBox("¿GENERAR PDF? ", vbYesNo, "AVISO")
If PREGUNTA = vbYes Then
CARPETA2
'ActiveSheet.PageSetup.PrintArea = ActiveSheet.UsedRange.Address
'Set rng = Range(ActiveSheet.UsedRange.Address)
x.Range(rf).ExportAsFixedFormat Type:=xlTypePDF, _
fileName:=NOMBRE, Quality:=xlQualityStandard, _
IncludeDocProperties:=True, IgnorePrintAreas:=True, _
From:=1, To:=10, OpenAfterPublish:=False
MsgBox "El archivo PDF fue generado en: " & NOMBRE & ".pdf"
Else
End
End If
End Sub
Private Sub OptionButton1_Click()
guardar_pdf
End SubPrivate Sub UserForm_Activate()
Set x = Worksheets("BOLETA")
x.SelectLIMPIA
With UserForm1
.Caption = "CONVERTIR PDF"
.Move 150, 10
End Withcelda = x.Range("B11").Value
a = 0
Do While celda <> Empty
celda = x.Range("B11").Offset(a, 0).Value
If celda = Empty Then Exit Do
ListBox1.AddItem celda
a = a + 67
LoopEnd Sub
Sub LIMPIA()
Set x = Worksheets("BOLETA")
Set y = Worksheets("TRABAJADOR")For Each PIC In y.Pictures
PIC.Delete
Next PIC'Set Z = y.Range("A1:M62")
Set Z = y.Range("A1:O67")
Z.ClearContentsEnd Sub
Sub CARPETA2()
Set fso = CreateObject("Scripting.FileSystemObject")
Dim archivos As String
Dim contador As Integerrespuesta = MsgBox(ActiveWorkbook.Path, vbYesNo, "USAR CARPETA")
If respuesta = vbYes Then
directorio = ActiveWorkbook.Path
Else
titulo = "Selecciona la ruta de tu carpeta"
On Error Resume Next
With CreateObject("shell.application")
directorio = .browseforfolder(0, titulo, 0).Items.Item.Path
End With: On Error GoTo 0
If directorio = "" Then
MsgBox "No has marcado ningún directorio.", , "Operación no válida"
End
Else
MsgBox "Ha seleccionado la siguiente ruta " & directorio
End If
End IfRES = MsgBox("¿Guardar con el nombre de: " & valor & ".pdf", vbYesNo, "AVISO")
If RES = vbYes Then
hoja = valor
Else
hoja = InputBox("TECLEA UN NOMBRE:", "AVISO")
If hoja = Empty Then End
End IfNOMBRE = directorio & "\" & hoja
End Sub
El siguiente codigo forma parte de la primera descripción, y esperando contar con su valioso aporte, quedo agradecido siempre de uds.
Dim NOMBRE As String
Sub guardar_pdf()
CARPETA
ActiveSheet.PageSetup.PrintArea = ActiveSheet.UsedRange.AddressSet rng = Range(ActiveSheet.UsedRange.Address)
rng.ExportAsFixedFormat Type:=xlTypePDF, _
fileName:=NOMBRE, Quality:=xlQualityStandard, _
IncludeDocProperties:=True, IgnorePrintAreas:=True, _
From:=1, To:=10, OpenAfterPublish:=False
Range("A1").SelectMsgBox "El archivo PDF fue generado en: " & NOMBRE & ".pdf"
End Sub
Sub CARPETA()
Set fso = CreateObject("Scripting.FileSystemObject")
Dim archivos As String
Dim contador As Integerrespuesta = MsgBox("Usar carpeta por default", vbYesNo, "AVISO")
If respuesta = vbYes Then
directorio = ActiveWorkbook.Path
Else
titulo = "Selecciona la ruta de tu carpeta"
On Error Resume Next
With CreateObject("shell.application")
directorio = .browseforfolder(0, titulo, 0).Items.Item.Path
End With: On Error GoTo 0
If directorio = "" Then
MsgBox "No has marcado ningún directorio.", , "Operación no válida"
End
Else
MsgBox "Ha seleccionado la siguiente ruta " & directorio
End If
End IfRES = MsgBox("¿Guardar con nombre por default?", vbYesNo, "AVISO")
If RES = vbYes Then
hoja = ActiveSheet.Name
Else
hoja = UCase(InputBox("TECLEA UN NOMBRE:", "AVISO"))
End IfNOMBRE = directorio & "\" & hoja
End Sub
'REVISAR ESTA RUTINA
Sub ajustar()
Range("a68").Select
n = Range("a68").Value
Do While ActiveCell <> Empty
Set x = ActiveCell.Resize(2, 2)
x.EntireRow.Insert
ActiveCell.Offset(69, 0).Select
Loop
End Sub
Sub forma()
UserForm1.Show
End Sub
Buenas noches Dante una pequeña duda : porque multiplico * 67 en esta línea. Range(ri & ":o" & numero * 67).Address - Adriel Ortiz Mangia
No lo sé, no es mi código. - Dante Amor
Buenas tardes amigo Adriel, el código Range(ri & ":o" & numero * 67).Address - se refiere a la cantidad columnas es decir desde la A hasta O y por la cantidad de filas es decir * 67. - Canon Sata
Gracias - Adriel Ortiz Mangia