Email each sheet as a separate PDF with its sheet name as the file name.

desnyder2001

New Member
Joined
Aug 4, 2017
Messages
12
I am trying to create a 1 Click button that will attach each sheet as a separate PDF file with the sheet name as the file name to an outlook email.
I am currently able to accomplish the above but it merges all the files into 1 PDF. They need to be separate.
 

Some videos you may like

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.

DanteAmor

Well-known Member
Joined
Dec 3, 2018
Messages
12,095
Office Version
2007
Platform
Windows
I am trying to create a 1 Click button that will attach each sheet as a separate PDF file with the sheet name as the file name to an outlook email.
I am currently able to accomplish the above but it merges all the files into 1 PDF. They need to be separate.

Try this:

Code:
Sub Macro6()
    Dim sh As Worksheet, wPath As String, wFile As String
    wPath = ThisWorkbook.Path & "\"
    For Each sh In Sheets
        wFile = wPath & sh.Name & ".pdf"
        sh.ExportAsFixedFormat Type:=xlTypePDF, Filename:=wFile, Quality:=xlQualityStandard, _
            IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
        Set dam = CreateObject("Outlook.Application").CreateItem(0)
        dam.To = "email@google.com"
        dam.Subject = "Subject"
        dam.Body = "body"
        dam.Attachments.Add wFile
        dam.Display
    Next
End Sub
 

desnyder2001

New Member
Joined
Aug 4, 2017
Messages
12
This worked exactly as you wrote it. Is there anyway that all the attachments can be in one email instead of an email for each attachment? That would oh so awesome
Thank you either way because if nothing else this is going to save a ton of time


Try this:

Code:
Sub Macro6()
    Dim sh As Worksheet, wPath As String, wFile As String
    wPath = ThisWorkbook.Path & "\"
    For Each sh In Sheets
        wFile = wPath & sh.Name & ".pdf"
        sh.ExportAsFixedFormat Type:=xlTypePDF, Filename:=wFile, Quality:=xlQualityStandard, _
            IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
        Set dam = CreateObject("Outlook.Application").CreateItem(0)
        dam.To = "email@google.com"
        dam.Subject = "Subject"
        dam.Body = "body"
        dam.Attachments.Add wFile
        dam.Display
    Next
End Sub
 

DanteAmor

Well-known Member
Joined
Dec 3, 2018
Messages
12,095
Office Version
2007
Platform
Windows
This worked exactly as you wrote it. Is there anyway that all the attachments can be in one email instead of an email for each attachment? That would oh so awesome
Thank you either way because if nothing else this is going to save a ton of time

Try this:

Code:
Sub Macro6()
    Dim sh As Worksheet, wPath As String, wFile As String
    wPath = ThisWorkbook.Path & "\"
    Set dam = CreateObject("Outlook.Application").CreateItem(0)
    dam.To = "email@goole.com"
    dam.Subject = "Subject"
    dam.Body = "body"
    For Each sh In Sheets
        wFile = wPath & sh.Name & ".pdf"
        sh.ExportAsFixedFormat Type:=xlTypePDF, Filename:=wFile, Quality:=xlQualityStandard, _
            IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
        dam.Attachments.Add wFile
    Next
    dam.Display
End Sub
 

desnyder2001

New Member
Joined
Aug 4, 2017
Messages
12
RESOLVED
Wow, that was awesome. Thank you
 

desnyder2001

New Member
Joined
Aug 4, 2017
Messages
12
RESOLVED: Email each sheet as a separate PDF with its sheet name as the file name.

Worked Perfect - Thank you very much
 

DanteAmor

Well-known Member
Joined
Dec 3, 2018
Messages
12,095
Office Version
2007
Platform
Windows
Re: RESOLVED: Email each sheet as a separate PDF with its sheet name as the file name.

Worked Perfect - Thank you very much
I'm glad to help you. I appreciate your kind comments.
 

Watch MrExcel Video

Forum statistics

Threads
1,101,749
Messages
5,482,640
Members
407,356
Latest member
fabioargenton

This Week's Hot Topics

  • Finding issue in If elseif else with For each Loop
    Finding issue in If elseif else with For each Loop I have tried this below code but i'm getting in Y column filled with W005. Colud you please...
  • MsgBox Error
    Hi Guys, I have the below error show up when i try and run my macro in File1 but works fine if i copy and paste the same code into file2. [ATTACH...
  • CELL FORMAT - IF CONDITION
    My Cell Format is [B]""0.00" Cr". [/B]But in the cell, it is showing 123.00 for editing. (123 is entry figure). (Data imported from other...
  • Show numbers nearly the same
    Is this possible. I have a number that can change very time eg 0.00001234 Then I have a lot of numbers 0.0000001, 0.0000002, 0.00000004...
  • Please i need your help to create formula
    I need a formula in cell B8 to do this >>if b1=1 then multiply ( cell b8) by 10% ,if b1=2 multiply by 20%,if=3 multiply by 30%. Thank you in...
  • Got error while adding column and filter
    Got error while adding column and filter In column Z has some like "Success" and "Error". I want to add column in AA if the Z cell value is...
Top