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

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December

DanteAmor

Well-known Member
Joined
Dec 3, 2018
Messages
12,208
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,208
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,208
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,102,665
Messages
5,488,175
Members
407,629
Latest member
bibsan

This Week's Hot Topics

  • Timer in VBA - Stop, Start, Pause and Reset
    [CODE=vba][/CODE] Option Explicit Dim CmdStop As Boolean Dim Paused As Boolean Dim Start Dim TimerValue As Date Dim pausedTime As Date Sub...
  • how to updates multiple rows in muliselect listbox
    Hello everyone. I need help with below code. code is only chaning 1st row in mulitiselect list box. i know issue with code...
  • Delete Row from Table
    I am trying to delete a row from a table using VBA using a named range to find what I need to delete. My Range is finding the right cell. In the...
  • Assigning to a variable
    I have a for each block where I want to assign the value in column 5 of the found row to the variable Serv. [CODE=vba] For Each ws In...
  • Way to verify information
    Hi All, I don't know what to call this formula, and therefore can't search. I have a spreadsheet with information I want to reference...
  • Active Cell Address – Inactive Sheet
    How to use VBA to get the cell address of the active cell in an inactive worksheet and then place that cell address in a location on the current...
Top