ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   After printing to PDFs. How do I attach them to an email? (https://www.excelbanter.com/excel-programming/374272-after-printing-pdfs-how-do-i-attach-them-email.html)

Calle

After printing to PDFs. How do I attach them to an email?
 
I use this code to print sheets to pdf files but how do I code a VBA macro to
attach the files to an email

s = Application.ActivePrinter
For i = 1 To 9
Err.Clear
On Error Resume Next
Application.ActivePrinter = "Adobe PDF på Ne0" & i & ":"
If Err.Number = 0 Then Exit For
On Error GoTo 0
Next
On Error GoTo 0
Worksheets("Kund data").PrintOut Copies:=1, ActivePrinter:= _
"Adobe PDF på Ne0" & i & ":", Collate:=True
Worksheets("Schakt dörr").PrintOut Copies:=1, ActivePrinter:= _
"Adobe PDF på Ne0" & i & ":", Collate:=True
Worksheets("Korg dörr").PrintOut Copies:=1, ActivePrinter:= _
"Adobe PDF på Ne0" & i & ":", Collate:=True

Application.ActivePrinter = s

I have tried this script but you have to define the name of the pdf. Is
there anyway to get the macro to know what file names and filepaths the new
pdfs I just created have?

Dim OutApp As Outlook.Application
Dim OutMail As Outlook.MailItem
Dim strbody As String
Dim cell As Range

Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(olMailItem)

With OutMail
..To = ""
..CC = ""
..BCC = ""
..Subject = ""
..Attachments.Add ("C:\wittur\offert.pdf")
..Body = strbody
..Display
End With
Set OutMail = Nothing
Set OutApp = Nothing

Tom Ogilvy

After printing to PDFs. How do I attach them to an email?
 
I don't have acrobat installed here, so I can't test it and tell - also,
Acrobat seems to have multiple ways to do this. In any event, this is an oft
discussed topic, so you might look here and see if you can find something
that helps:

http://tinyurl.com/q8fyd

--
Regards,
Tom Ogilvy


"Calle" wrote:

I use this code to print sheets to pdf files but how do I code a VBA macro to
attach the files to an email

s = Application.ActivePrinter
For i = 1 To 9
Err.Clear
On Error Resume Next
Application.ActivePrinter = "Adobe PDF på Ne0" & i & ":"
If Err.Number = 0 Then Exit For
On Error GoTo 0
Next
On Error GoTo 0
Worksheets("Kund data").PrintOut Copies:=1, ActivePrinter:= _
"Adobe PDF på Ne0" & i & ":", Collate:=True
Worksheets("Schakt dörr").PrintOut Copies:=1, ActivePrinter:= _
"Adobe PDF på Ne0" & i & ":", Collate:=True
Worksheets("Korg dörr").PrintOut Copies:=1, ActivePrinter:= _
"Adobe PDF på Ne0" & i & ":", Collate:=True

Application.ActivePrinter = s

I have tried this script but you have to define the name of the pdf. Is
there anyway to get the macro to know what file names and filepaths the new
pdfs I just created have?

Dim OutApp As Outlook.Application
Dim OutMail As Outlook.MailItem
Dim strbody As String
Dim cell As Range

Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(olMailItem)

With OutMail
.To = ""
.CC = ""
.BCC = ""
.Subject = ""
.Attachments.Add ("C:\wittur\offert.pdf")
.Body = strbody
.Display
End With
Set OutMail = Nothing
Set OutApp = Nothing



All times are GMT +1. The time now is 03:17 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com