SanFelippo
Board Regular
- Joined
- Apr 4, 2017
- Messages
- 124
Hi,
I have this nifty macro that saves a temp copy of the workbook and attaches it to an email. After a copy has been attached, it then deletes that temp copy. It works perfectly right now, but I was wondering if it could be possible to have it also save the workbook as a PDF and attach it to the email as well? I would want it to then delete the temp PDF copy it made after it is attached, just like it does the Excel copy.
Any ideas how to do that?
I have this nifty macro that saves a temp copy of the workbook and attaches it to an email. After a copy has been attached, it then deletes that temp copy. It works perfectly right now, but I was wondering if it could be possible to have it also save the workbook as a PDF and attach it to the email as well? I would want it to then delete the temp PDF copy it made after it is attached, just like it does the Excel copy.
Any ideas how to do that?
Code:
[Sub Submit_Button_Tab_1()
If Range("B5").Value = "No" Then
'Working in Excel 2000-2016
'Mail a copy of the ActiveWorkbook with another file name
Dim wb1 As Workbook
Dim TempFilePath As String
Dim TempFileName As String
Dim FileExtStr As String
Dim OutApp As Object
Dim OutMail As Object
With Application
.ScreenUpdating = False
.EnableEvents = False
End With
Set wb1 = ActiveWorkbook
'Make a copy of the file/Open it/Mail it/Delete it
'If you want to change the file name then change only TempFileName
TempFilePath = Environ$("temp") & "\"
TempFileName = Format(Now, "mm-dd-yy") & " " & wb1.Name
'FileExtStr = "." & LCase(Right(wb1.Name, Len(wb1.Name) - InStrRev(wb1.Name, ".", , 1)))
wb1.SaveCopyAs TempFilePath & TempFileName & FileExtStr
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With OutMail
.To = "[EMAIL="SomeonesEmail@abna.com"]SomeonesEmail@abna.com[/EMAIL]"
.cc = ""
.BCC = ""
.Subject = "Subject Line"
.Body = ""
.Attachments.Add TempFilePath & TempFileName & FileExtStr
'You can add other files also like this
'.Attachments.Add ("C:\test.txt")
'.Send or use'
.Display
End With
On Error GoTo 0
'Delete the file
Kill TempFilePath & TempFileName & FileExtStr
Set OutMail = Nothing
Set OutApp = Nothing
With Application
.ScreenUpdating = True
.EnableEvents = True
End With
Else
MsgBox "Can only submit on this sheet if 2nd HMDA Determination Question is answered 'No'"
End If
End Sub
/CODE]