Visual Basic - Macro para imprimir

Life is soft - evento anual de software empresarial
 
Vista:

Macro para imprimir

Publicado por Gustavo (4 intervenciones) el 10/06/2019 11:29:58
Buenos días,

Se que hay muchos mensajes con temas referentes a la impresión, pero no soy capaz de editar el código para hacer lo que necesito. Agradezco cualquier ayuda.

Tengo un excel en el que quiero imprimir una pagina generada a partir de 3 variables seleccionadas por el usuario. Con una de esas tres variables, necesito o bien:

1- usarla como numero de paginas a imprimir (imprimir de 1 - variable)

2- usarla para definir el area de impresión


No se cual es la mejor solución y como escribirla. Dejo aqui la macro. Gracias por adelantado

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
Sub Imprimir_Envío()
'
' Imprimir_Envío Macro
'
 
'Revisa las celdas
    existe = False
    For Each D In Range("C3:C5")
        If D.Value = "" Then
            celdas = celdas & " " & D.Address(False, False)
            existe = True
        End If
    Next
    If existe Then
        MsgBox "Falta información para el envío : " & celdas
        Exit Sub
    End If
 
Dim def As String
Dim PdfPrint As String
Dim LaserPrint As String
def = Application.ActivePrinter
PdfPrint = "PDFCreator en Ne00:"
LaserPrint = "MicrosoftXPSDocumentWriter en Ne01:"
Application.ActivePrinter = PdfPrint
    Sheets("Etiqueta").Select
    ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True, _
        IgnorePrintAreas:=False
 
    Sheets("Listado de envíos").Select
    ActiveSheet.Unprotect
    Sheets("Etiqueta").Select
    Range("N2:U2").Select
    Selection.Copy
    Range("N5").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    ActiveWindow.SmallScroll ToRight:=3
    Sheets("Listado de envíos").Select
    Range("A2:H2").Select
    Application.CutCopyMode = False
    Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
    Sheets("Etiqueta").Select
    Selection.Copy
    Application.CutCopyMode = False
    Selection.Cut
    Sheets("Listado de envíos").Select
    Range("A2").Select
    ActiveSheet.Paste
    Sheets("Listado de envíos").Select
    Range("A3:H3").Select
    Selection.Copy
    Range("A2:H2").Select
    Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
        SkipBlanks:=False, Transpose:=False
    Application.CutCopyMode = False
    Application.ActivePrinter = def
    Sheets("IMPRIMIR").Select
    Range("C3:C5").Select
    ActiveCell.Activate
    Selection.ClearContents
    Range("C3").Select
Application.DisplayAlerts = False
'guardar libro
    ActiveWorkbook.Save
Application.DisplayAlerts = True
End Sub
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

Macro para imprimir

Publicado por Gustavo (4 intervenciones) el 10/06/2019 12:43:38
Estoy intentando definir la variable numpag y usarla como (printout From= 1, To= numpag

Me da error por supuesto....

1
2
3
4
5
6
7
8
9
10
11
12
13
14
Dim numpag As String
Dim BeginPage, EndPage, NumCopies, i
Dim def As String
Dim PdfPrint As String
Dim LaserPrint As String
def = Application.ActivePrinter
PdfPrint = "PDFCreator en Ne00:"
LaserPrint = "MicrosoftXPSDocumentWriter en Ne01:"
Sheets("Etiqueta").Select
numpag = Range("C4")
Application.ActivePrinter = PdfPrint
    Sheets("Etiqueta").Select
    ActiveWindow.SelectedSheets.PrintOut From:=1, To:=numpag, Copies:=1, Collate _
        :=True, IgnorePrintAreas:=False
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

Macro para imprimir

Publicado por Gustavo (4 intervenciones) el 20/06/2019 23:21:43
Realmente nadie sabe que falla con la variable o como se puede hacer????
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

Macro para imprimir

Publicado por Gustavo (4 intervenciones) el 23/06/2019 00:09:08
Gracias parece que he avanzado añadiendo lo que indicas.

Ahora me da otro error; error '1104' en tiempo de ejecución: Error en el método 'PrintOut' de objeto 'Sheets'

Al darle a depurar me resalta la siguiente línea:

ActiveWindow.SelectedSheets.PrintOut From:=1, To:=numpag, Copies:=1, Collate _
:=True, IgnorePrintAreas:=False

Sabéis que le falla ahora??
Necesito terminar esta macro para entregar el archivo, por favor ayuda..
Gracias por adelantado
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar