Hey all, I'm trying to add an if then statement into my Email code. The if then statement is this:
Pretty much I want the Email code to run the if then before populating the email to remove information that is not needed, but I keep getting errors. Any ideas would be much appreciated!![]()
Sub ClearW1D1M1() If Sheet2.Range("B52").Value = 0 Then Sheet2.Range("A52:D52").ClearContents If Sheet2.Range("B53").Value = 0 Then Sheet2.Range("A53:D53").ClearContents End Sub And the full Email code is here: Sub MailW1D1M1() 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 = Sheet2.Range("B3") .CC = Sheet2.Range("D3") .BCC = "" .Subject = Sheet2.Range("B13") .display Set xInspect = newEmail.GetInspector Set pageEditor = xInspect.WordEditor Sheet2.Range("A45:D53").Copy pageEditor.Application.Selection.End = pageEditor.Application.Selection.Start pageEditor.Application.Selection.PasteAndFormat (wdFormatPlainText) .display Set pageEditor = Nothing Set xInspect = Nothing .display End With Set newEmail = Nothing Set outlook = Nothing End Sub
Thanks
Bookmarks