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: