Forum Discussion
Bkroening
Jun 08, 2022Copper Contributor
Command send email and reset at same time
Hi I need help getting the command button to send an email and reset the form at the same time. Currently it sends the email but reset it before delivering the data in the sheet. Please help
Sub Test1()
Dim xOutlookObj As Object
Dim xOutApp As Object
Dim xOutMail As Object
Dim xMailBody As String
On Error Resume Next
Set xOutApp = CreateObject("Outlook.Application")
Set xOutMail = xOutApp.CreateItem(0)
On Error Resume Next
With xOutMail
.To = "email address removed for privacy reasons"
.CC = ""
.BCC = ""
.Subject = "Shot Peen " & Range("B4") & Range("F2") & Range("F3")
.Body = xMailBody
.Attachments.Add ActiveWorkbook.FullName
.Send
End With
On Error GoTo 0
Set xOutMail = Nothing
Set xOutApp = Nothing
MsgBox "Dashboard Data Sent"
End Sub
Sub Test2()
Sheets("Shot Peen").Range("B2").Value = ""
Sheets("Shot Peen").Range("B4").Value = ""
Sheets("Shot Peen").Range("B7:I7").Value = ""
Sheets("Shot Peen").Range("F2").Value = ""
Sheets("Shot Peen").Range("F3").Value = ""
Sheets("Shot Peen").Range("B11:f18").Value = ""
Application.ScreenUpdating = True
End Sub
- If you add
ActiveWorkbook.Save
at the beginning of the code, does that overcome the problem? - NikolinoDEGold Contributor
none Microsoft site
I can only recommend one of the best sites when it comes to sending emails.
I know I don't know anything (Socrates)