Additonal PDFs to email via VBA

MrHydrant1857

New Member
Joined
Mar 29, 2019
Messages
35
Need help with sending multiple pdfs via outlook with VBA. I am using a workbook with multiple sheets. when I click on my macro in either sheet it will convert the excel file to a PDF. it will then prompt if I would like to send in email. if I click no it simply saves the pdf in the appropriate file then saves the excel file. what I am looking for is to be able to click no do not send email on my first click of the macro but then create another pdf that I will send in email with the pdf I created just before. I am familiar with the VBA code to add another attachment but the way I am saving my pdfs with unique names I do not know how to call the specific one (previous one) I want to attach. the code is below. if anyone can help me out that would be great!!

Code:
Dim Filename As String
strTime = Range("B13") & Range("C13").Value
strName = (" (#") & Range("B19").Value & "-" & Range(" G12").Value & ") " & ".pdf"
strXTime = Range("B13") & Range("C13").Value
If Len(Dir("G:\SALES\Quotes\Chris Lang" & Year(Date), vbDirectory)) = 0 Then
        MkDir "G:\SALES\Quotes\Chris Lang" & Year(Date)
    End If
     
     
     ' Check for month folder and create if needed
    If Len(Dir("G:\SALES\Quotes\Chris Lang" & Year(Date) & "" & MonthName(Month(Date), False), vbDirectory)) = 0 Then
        MkDir "G:\SALES\Quotes\Chris Lang" & Year(Date) & "" & MonthName(Month(Date), False)
    End If
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:="G:\SALES\Quotes\Chris Lang" & Year(Date) & "" & MonthName(Month(Date), False) & "" & strTime & strJName & strName, OpenAfterPublish:=False
Dim OutLookApp As Object
Dim OutLookMailItem As Object
Dim myAttachments As Object
Set OutLookApp = CreateObject("OutLook.Application")
Set OutLookMailItem = OutLookApp.CreateItem(0)
Set myAttachments = OutLookMailItem.Attachments
Dim Answer As String
Dim MyNote As String

    'Place your text here
    MyNote = "Send Quote as Email?"
    'Display MessageBox
    Answer = MsgBox(MyNote, vbQuestion + vbYesNo, "Email")
    If Answer = vbNo Then
        'Code for No button Press
        MsgBox "Quote Saved"
    Else
        'Code for Yes button Press
        With OutLookMailItem
        .Display
End With
Signature = OutLookMailItem.Body
       With OutLookMailItem
.To = Range("G15").Value
.Subject = "Kupferle Quote: " & "#" & Range("B19").Value & "-" & Range("G12").Value
myAttachments.Add "G:\SALES\Quotes\Chris Lang" & Year(Date) & "" & MonthName(Month(Date), False) & "" & strTime & strName
'.send
.Display
End With
Set OutLookMailItem = Nothing
Set OutLookApp = Nothing
    End If
ActiveWorkbook.SaveCopyAs Filename:="G:\SALES\Quotes\Chris Lang\Excel Files" & strName & strJName & strXTime & ".xlsm"
Range("C13").Value = Range("C13").Value + 1
ActiveWorkbook.Save
'End If
'End If
exitHandler:
    Exit Sub
errHandler:
    MsgBox "Could not create PDF file"
    Resume exitHandler

End Sub
 
Last edited by a moderator:

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
One option is to create a temporary sheet. Save your files as pdf and store the name of the file in a column in temporary sheet. You can save the pdf you want and go accumulating the names in the temporary sheet, then go to the temporary sheet and select the cells with the names of the files you want to send and then click on another button to send exclusive mail.
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top