Required Field

tbrynard01

Board Regular
Joined
Sep 20, 2017
Messages
129
Office Version
  1. 365
Platform
  1. Windows
I have the following code in a button and would like to add the code to check for required fields on the spreadsheet before it sends the email and to not send unless all the required fields are required, but not sure where to put it in this code - Thank you!:

VBA Code:
Sub Email2()


' Keyboard Shortcut: Ctrl+Shift+S

'

    Range("A3").Select

    Selection.End(xlDown).Select

    ActiveWorkbook.Save

 

Dim outlook As Object

Dim newEmail As Object

Dim xInspect As Object

Dim pageEditor As Object


Set outlook = CreateObject("Outlook.Application")

Set newEmail = outlook.CreateItem(0)


With newEmail

    .To = Sheet8.Range("B21").Text

    .CC = Sheet8.Range("G21").Text

    .BCC = ""

    .Subject = "MHR Request"

    .Body = ""

    .display

 

    Set xInspect = newEmail.GetInspector

    Set pageEditor = xInspect.WordEditor

 

    Sheet8.Range("A1:F20").Copy

 

    pageEditor.Application.Selection.Start = Len(.Body)

    pageEditor.Application.Selection.End = pageEditor.Application.Selection.Start

    pageEditor.Application.Selection.PasteAndFormat (wdFormatPlainText)

    .display

    .Send

    Set pageEditor = Nothing

End With


Set newEmail = Nothing

Set outlook = Nothing

  

 

Call ClearForm


End Sub
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
What are the required fields?
 
Upvote 0
I'm assuming the required cells are on the sheet the macro is run from. Immediately after the Sub line add this block.
VBA Code:
Dim reqdRng
Set reqdRng = Range("C3:C5")
If Application.CountA(reqdRng) <> reqdRng.Count Then
    MsgBox "All cells in range: " & reqdRng.Address(0, 0) & " must have entries. Please comply then run this macro again."
    Exit Sub
End If
 
Upvote 0
You are welcome - thanks for the reply.
 
Upvote 0

Forum statistics

Threads
1,214,895
Messages
6,122,128
Members
449,066
Latest member
Andyg666

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top