I have this VBA to auto generate an email upon completion of a form and a submit button, however, due to consistent issues with their information I need to add the ability to not create the email and attach the form if the text boxes are not filled out. Does anyone know of a means to do that by adding to this VBA macro?
Thank you!!
Sub SendWorkBook()
Dim mystr As String
Dim OutlookApp As Object
Dim OutlookMail As Object
Set OutlookApp = CreateObject("Outlook.Application")
Set OutlookMail = OutlookApp.CreateItem(0)
Call YesNoMessageBox
mystr = Sheets("Cover Sheet").Range("AL14").Value 'change sheet name
On Error Resume Next
With OutlookMail
.To = ""
.CC = ""
.BCC = ""
.Subject = mystr
.Body = "Hello," & vbNewLine & vbNewLine & "This DAF is being submitted for your processing." & vbNewLine & vbNewLine & "Thank You!"
.Attachments.Add Application.ActiveWorkbook.FullName
.Send
End With
Set OutlookMail = Nothing
Set OutlookApp = Nothing
End Sub
Sub YesNoMessageBox()
Dim Answer As String
Dim MyNote As String
MyNote = "Have you saved this document?"
Answer = MsgBox(MyNote, vbQuestion + vbYesNo, "Thank You!")
If Answer = vbNo Then
MsgBox "This document will not be sent at this time. Please save your document and then click SUBMIT once more. Thank you."
End
Else
MsgBox "Your Document will now be forwarded to Document Control. Thank you!"
MyNote = "Are you sure you wish to send your submittal at this time?"
Answer = MsgBox(MyNote, vbQuestion + vbYesNo, "Thank You!")
End If
End Sub
Thanks everyone for taking the time to look at this and help!!
Thank you!!
Sub SendWorkBook()
Dim mystr As String
Dim OutlookApp As Object
Dim OutlookMail As Object
Set OutlookApp = CreateObject("Outlook.Application")
Set OutlookMail = OutlookApp.CreateItem(0)
Call YesNoMessageBox
mystr = Sheets("Cover Sheet").Range("AL14").Value 'change sheet name
On Error Resume Next
With OutlookMail
.To = ""
.CC = ""
.BCC = ""
.Subject = mystr
.Body = "Hello," & vbNewLine & vbNewLine & "This DAF is being submitted for your processing." & vbNewLine & vbNewLine & "Thank You!"
.Attachments.Add Application.ActiveWorkbook.FullName
.Send
End With
Set OutlookMail = Nothing
Set OutlookApp = Nothing
End Sub
Sub YesNoMessageBox()
Dim Answer As String
Dim MyNote As String
MyNote = "Have you saved this document?"
Answer = MsgBox(MyNote, vbQuestion + vbYesNo, "Thank You!")
If Answer = vbNo Then
MsgBox "This document will not be sent at this time. Please save your document and then click SUBMIT once more. Thank you."
End
Else
MsgBox "Your Document will now be forwarded to Document Control. Thank you!"
MyNote = "Are you sure you wish to send your submittal at this time?"
Answer = MsgBox(MyNote, vbQuestion + vbYesNo, "Thank You!")
End If
End Sub
Thanks everyone for taking the time to look at this and help!!
Last edited: