VBA & Macro Problems

Send Excel Data by Email and Clear Input Cells with VBA

Jason MillerJason Miller Nov 22, 2026 869 views

Question details

The user wants to email completed Excel template data and then clear only the editable input cells.

Send Excel Data by Email and Clear Input Cells with VBA
Product
Microsoft Excel
Device & OS
not provided
Scenario
A VBA macro sends data from a completed template and prepares the input cells for the next entry.
Observed behavior
The desired result is an email containing the input data, followed by cleared input cells while formulas and formatting remain intact.
Before you start

Identify the worksheet name and editable cells, and make sure the target range does not include formulas. The example uses classic Outlook for Windows with a configured email account and a macro-enabled Excel workbook.

Solution 1Recommended

Send the email and clear the input range in one Excel VBA macro

Use this approach when Outlook is available and you want to clear the inputs only after Outlook accepts the send command.

ClearContents removes cell contents but retains formatting. Avoid Cells.Clear, which clears the entire worksheet, including formatting and formulas.

1
Open the VBA editor

In Excel, press Alt+F11, then choose Insert > Module.

2
Add and customize the macro

Paste the code below into the module. Replace Sheet1, B2:B10, the recipient, and the subject with your actual values. Include only editable cells in the clear range. Sub SendAndClearInputs() Dim ws As Worksheet Dim inputRange As Range Dim cell As Range Dim outlookApp As Object Dim mail As Object Dim bodyText As String Dim submitted As Boolean On Error GoTo HandleError Set ws = ThisWorkbook.Worksheets("Sheet1") Set inputRange = ws.Range("B2:B10") For Each cell In inputRange.Cells bodyText = bodyText & cell.Address(False, False) & ": " & cell.Text & vbCrLf Next cell Set outlookApp = CreateObject("Outlook.Application") Set mail = outlookApp.CreateItem(0) With mail .To = "recipient@example.com" .Subject = "Completed template data" .Body = bodyText .Send End With submitted = True inputRange.ClearContents MsgBox "Email submitted to Outlook and input cells cleared." Exit Sub HandleError: If submitted Then MsgBox "The email was submitted, but the input cells could not be cleared: " & Err.Description Else MsgBox "The macro did not complete the send step. Input cells were not cleared: " & Err.Description End If End Sub

3
Save and run the macro

Save the workbook as an Excel Macro-Enabled Workbook (.xlsm). In Excel, press Alt+F8, select SendAndClearInputs, and choose Run.

4
Check the result

Check Outlook's Outbox or Sent Items and confirm that only the intended input cells were cleared. If clearing fails, check whether the cells are protected.

Send the email and clear the input range in one Excel VBA macro
Sending is not delivery confirmation: The Outlook Send command submits the message; it does not confirm delivery. Outlook security prompts or account settings may affect sending. Check the message status before retrying to avoid duplicates.
Free Microsoft Office alternative

Work with Excel templates in WPS Office

WPS Office is a free, lightweight alternative with a familiar spreadsheet interface and compatibility with common Excel formats, making it easy to move everyday template work between office suites. The Excel and Outlook VBA automation described above is not guaranteed to work in WPS.

Edit spreadsheet templates and clear selected input cells manuallyOpen and edit common Microsoft Excel XLSX and XLS filesUse a familiar interface for everyday spreadsheet tasksGet started with a free, lightweight office suite
microsoft office alternative - wps office

Frequently Asked Questions

How do I clear inputs without deleting formulas or formatting?

Use a range containing only editable cells, such as ws.Range("B2:B10").ClearContents. ClearContents retains formatting, but it will remove formulas if they are inside the selected range.

What happens if the email send command fails?

In the example, the error handler runs before ClearContents if the send step raises an error, so the input cells are not cleared. Check Outlook's Outbox and Sent Items before retrying.

Can I review the email before sending it?

You can replace .Send with .Display to review the message in Outlook. However, the macro will continue immediately after displaying it, so remove the automatic ClearContents line or use a separate clearing action after you send.

Why do I need classic Outlook for this example?

The macro uses CreateObject("Outlook.Application") to control Outlook through its desktop automation interface. It requires a supported classic Outlook installation and a configured account; it is not an example for new Outlook or webmail.

Where should I save the VBA macro?

In Excel, press Alt+F11 and choose Insert > Module, then paste the macro. Save the workbook as an .xlsm file so it can retain the VBA code.