Hi,
I'm creating a form which users will complete and email. I need certain mandatory fields to be completed.
I have code which checks if a cell is empty, if it is it prompts a message box and turns the corresponding question cell red. if it is not blank, it will create a pdf and send an email.
This is working however I have several mandatory cells and I'm not sure the best way to write the code to test all mandatory cells before moving on to send the email. if any of them is blank I want to flag the message box and turn any/all blank questions red.
Here is what I have so far:
Sub RDB_Worksheet_Or_Worksheets_To_PDF_And_Create_Mail()
If IsEmpty(Range("B2").Value) = True Then
MsgBox "Please Complete Mandatory Fields"
Range("A2").Font.ColorIndex = 3
Else
Dim FileName As String
If ActiveWindow.SelectedSheets.Count > 1 Then
MsgBox "There is more then one sheet selected," & vbNewLine & _
"be aware that every selected sheet will be published"
End If
'Call the function with the correct arguments
'Tip: You can also use Sheets("YourSheetName") instead of ActiveSheet in the code(sheet not have to be active then)
FileName = RDB_Create_PDF(Source:=ActiveSheet, _
FixedFilePathName:="", _
OverwriteIfFileExist:=True, _
OpenPDFAfterPublish:=False)
'For a fixed file name use this in the FixedFilePathName argument
'FixedFilePathName:="C:\Users\Ron\Test\YourPdfFile.pdf"
If FileName <> "" Then
RDB_Mail_PDF_Outlook FileNamePDF:=FileName, _
StrTo:="CorporateInsuranceMotorNewClaims@nfumutual.co.uk", _
StrCC:="", _
StrBCC:="", _
StrSubject:="New Claim Notification", _
Signature:=True, _
Send:=False, _
StrBody:="<H3><B>Please find attached new claim notification</B></H3><br>"
Else
MsgBox "Not possible to create the PDF, possible reasons:" & vbNewLine & _
"Microsoft Add-in is not installed" & vbNewLine & _
"You Canceled the GetSaveAsFilename dialog" & vbNewLine & _
"The path to Save the file in arg 2 is not correct" & vbNewLine & _
"You didn't want to overwrite the existing PDF if it exist"
End If
End If
End Sub
Many thanks in advance!
Bookmarks