Visual Basic para Aplicaciones - Macro para Imprimir

Life is soft - evento anual de software empresarial
 
Vista:

Macro para Imprimir

Publicado por Andrey (2 intervenciones) el 12/08/2016 22:15:10
Buenas tardes,

Me pueden ayudar con esta inquietud que tengo por favor...

Tengo la siguiente macro, pero quisiera saber si es posible de que el archivo que me genera en pdf y el cual envía por correo electrónico, también se imprimiera, ¿ es posible? si es así, alguien me puede ayudar por favor diciéndome qué instrucción le debo agregar.

Muchas gracias!!!


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
Sub ()
 
Dim FechaHora As Date
Dim StringFecha As String
 
FechaHora = Now
 
StringFecha = FechaHora
 
StringFecha = Replace(StringFecha, "/", "-")
 
StringFecha = Replace(StringFecha, ":", "_")
 
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
Filename:=ThisWorkbook.Path & "\ ", Quality:=xlQualityStandard, _
IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=True
 
 strReportName = " f"
   Dim objOutlook As Object
   Dim objMail As Object
   Dim objOutlookAttach As Object
   Set objOutlook = CreateObject("Outlook.Application")
      Set objMail = objOutlook.CreateItem(olMailItem)
   Set objOutlookAttach = objOutlook.CreateItem(olAttachMents)
      With objMail
         'A quien va dirigido el correo
         .To = ""
         'Se especifica el asunto
         .Subject = " "
         'Se escriben el o los archivos a adjuntar en el mail
 
         .Attachments.Add " "
         'Se manda el mensaj
         .Send
      End With
   'Se cierran todos los objetos utilizados
   Set objMail = Nothing
   Set objOutlook = Nothing
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
Imágen de perfil de Antoni Masana
Val: 1.134
Oro
Ha mantenido su posición en Visual Basic para Aplicaciones (en relación al último mes)
Gráfica de Visual Basic para Aplicaciones

Macro para Imprimir

Publicado por Antoni Masana (498 intervenciones) el 19/08/2016 08:10:01
Solo tienes que añadir esta línea a tu Macro al principio o al final

1
2
3
ActiveWindow.SelectedSheets.PrintOut Copies:=1, _
                                     Collate:=True, _
                                     IgnorePrintAreas:=False


Este seria el resultado


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
Sub Macro_PDF ()
   Dim FechaHora As Date
   Dim StringFecha As String
   Dim objOutlook As Object
   Dim objMail As Object
   Dim objOutlookAttach As Object
 
   FechaHora = Now
   StringFecha = FechaHora
   StringFecha = Replace(StringFecha, "/", "-")
   StringFecha = Replace(StringFecha, ":", "_")
   ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
                                   Filename:=ThisWorkbook.Path & "\ ", _
                                   Quality:=xlQualityStandard, _
                                   IncludeDocProperties:=True, _
                                   IgnorePrintAreas:=False,
                                   OpenAfterPublish:=True
   strReportName = " f"
   Set objOutlook = CreateObject("Outlook.Application")
   Set objMail = objOutlook.CreateItem(olMailItem)
   Set objOutlookAttach = objOutlook.CreateItem(olAttachMents)
   With objMail
       'A quien va dirigido el correo
       .To = ""
       'Se especifica el asunto
       .Subject = " "
       'Se escriben el o los archivos a adjuntar en el mail
       .Attachments.Add " "
        'Se manda el mensaj
        .Send
   End With
  'Se cierran todos los objetos utilizados
   Set objMail = Nothing
   Set objOutlook = Nothing
 
   ActiveWindow.SelectedSheets.PrintOut Copies:=1, _
                                        Collate:=True, _
                                        IgnorePrintAreas:=False
End Sub

Saludos
\\//_
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