El documento contiene códigos para limpiar celdas y rangos en una hoja de cálculo, imprimir una factura, y copiar datos de una factura a una hoja base. También incluye subrutinas para imprimir un reporte, exportar una hoja a PDF e imprimirla, y limpiar los campos de ingreso de datos luego de copiar la factura.
1. CODIGOS PARA EL MODULO 1
Sub limpieza()
ActiveSheet.Range("C6,F4").Value = ""
ActiveSheet.Range("A10:B17").Value = ""
End Sub
Sub Imprimir()
' imprimir Macro
On Error Resume Next
Sheets("FACTURA").Activate
ActiveSheet.PrintPreview
End Sub
CODIGOS PARA EL BOTON IMPRIMIR Y GUARDAR
'imprimir
Call Imprimir
'rutina que graba la factura en hoja base
'se busca la primer fila libre en hoja Fact
filalibre = Sheets("Base").Range("A1048576").End(xlUp).Row + 1
'se pasarán los datos desde la 1er fila de items
ActiveSheet.Range("A10").Select
fila = 10
While ActiveCell.Value <> ""
'copiamos datos fijos ajustando nro col
Sheets("Base").Cells(filalibre, 2) = ActiveSheet.Range("F4") 'NRO FACT
Sheets("Base").Cells(filalibre, 1) = ActiveSheet.Range("B4") 'FECHA
Sheets("Base").Cells(filalibre, 3) = ActiveSheet.Range("C6") 'CLIENTE
'otros datos del encabezado
'copiamos lista de items
Sheets("Base").Cells(filalibre, 4) = ActiveCell.Offset(0, 0) 'CANT
Sheets("Base").Cells(filalibre, 5) = ActiveCell.Offset(0, 1) 'COD PROD
Sheets("Base").Cells(filalibre, 6) = ActiveCell.Offset(0, 2) 'PROD
Sheets("Base").Cells(filalibre, 7) = ActiveCell.Offset(0, 3) 'DESCRIPC
Sheets("Base").Cells(filalibre, 8) = ActiveCell.Offset(0, 4) 'PRECIO UNIT
Sheets("Base").Cells(filalibre, 9) = ActiveCell.Offset(0, 5) 'PRECIO TOT
'incremento la variable fila para repetir el bucle
filalibre = filalibre + 1
'repito el bucle para los items siguientes
ActiveCell.Offset(1, 0).Select
Wend
'una vez concluída la copia debiera limpiarse el form de datos
'para el ingreso de nueva factura
Call limpieza
2. 1
Sub Imprimirreporte()
Sheet63.printout 1, 2
End sub
2
Sub Macro1()
Sheets("Hoja2").Activate
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
"C:Documents and SettingsUdeAMis documentos" & _
Sheets(1).Range("B4").Value & ".pdf", Quality:= _
xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, _
OpenAfterPublish:=True
ExecuteExcel4Macro "PRINT(1,,,1,,,,,,,,2,,,TRUE,,FALSE)"
Sheets("Hoja1").Activate
End Sub