KlausW
Active Member
- Joined
- Sep 9, 2020
- Messages
- 458
- Office Version
- 2016
- Platform
- Windows
Hi, I use this VBA code to send email with attached file, it works really well. I have set it to run a VBA code after but it doesn't do that, anyone who can help why it doesn't work.
Any help will be appreciated.
Best regards
Klaus W
Any help will be appreciated.
Best regards
Klaus W
VBA Code:
Sub Mail_workbook_Outlook()
Dim OutApp As Object
Dim OutMail As Object
Dim sndEmail As String
Dim toEmail As String
Dim ccEmail As String
Dim bccEmail As String
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With OutMail
.To = Sheets("Stamdata").Range("j1").Value
.CC = ""
.BCC = ""
.Subject = Sheets("Stamdata").Range("b1").Value
.Body = Range("n1").Value & vbNewLine & vbNewLine & Range("n4").Value & vbNewLine & _
Range("n5").Value & vbNewLine & Range("n6").Value & vbNewLine & Range("n7").Value & vbNewLine & _
Range("n8").Value
.Attachments.Add Range("I2") & Sheets("Stamdata").Range("B1").Value & ".pdf" 'attaches pdf file
.Display '<-- .Display will show the email first for review
'.Send '<-- .Send will auto send email without review
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
Clear_All
End Sub
Sub Clear_All()
Dim Ws As Worksheet
For Each Ws In ActiveWorkbook.Worksheets
Ws.Range("A47:a55").ClearContents
Next Ws
DeleteAllPics
End Sub
Sub DeleteAllPics()
Dim Pic As Object
For Each Pic In ActiveSheet.Pictures
Sheets("Bilag").Select
Range("a1:a20").Select
Range("a1:a20").ClearContents
Pic.Delete
Next Pic
End Sub