How To Mail the selection using VBA in Microsoft Excel?
Tags: tomailtheselection, vbamacros
Published: 2021-09-30 05:38:18

---
title: How To Mail the selection using VBA in Microsoft Excel?
published: true
date: 2021-09-28 08:20:15 UTC
tags: ToMailTheSelection,VBAMacros
canonical_url: https://geekexcel.com/how-to-mail-the-selection-using-vba-in-microsoft-excel/
---

In this tutorial, we will guide you on how to **mail the selection using VBA** in Microsoft Excel. Let’s get them below!! Get an official version of MS Excel from the following link: **[https://www.microsoft.com/en-in/microsoft-365/excel](https://www.microsoft.com/en-in/microsoft-365/excel)**

## Example

- Firstly, in the Excel Worksheet, you have to go to the  **Developer Tab.**
- Then, you need to ** ** select the  **Visual Basic**  option under the  **Code**  section.

![Select Visual Basic](https://geekexcel.com/wp-content/uploads/2021/09/Select-Visual-Basic-9-1024x180.png)<figcaption>Select Visual Basic</figcaption>

- Now, you have to  **copy and paste the code**  given below.

```
Sub Mail_Selection()
    Dim strDate As String
    Dim Addr As String
    Dim rng As Range
    If ActiveWindow.SelectedSheets.Count > 1 Or Selection.Areas.Count > 1 Then Exit Sub
    Application.ScreenUpdating = False
    Addr = Selection.Address
    ActiveSheet.Copy
    ActiveSheet.Pictures.Delete
    With Cells
        .EntireColumn.Hidden = False
        .EntireRow.Hidden = False
    End With
    Range(Addr).Select
    Set rng = Selection
    Application.GoTo rng, True
    With rng.EntireColumn
        .Hidden = True
        rng(1).EntireRow.SpecialCells(xlVisible).EntireColumn.Clear
        rng(1).EntireRow.SpecialCells(xlVisible).EntireColumn.Hidden = True
        .Hidden = False
    End With
    With rng.EntireRow
        .Hidden = True
        rng(1).EntireColumn.SpecialCells(xlVisible).EntireRow.Clear
        rng(1).EntireColumn.SpecialCells(xlVisible).EntireRow.Hidden = True
        .Hidden = False
    End With
    Application.GoTo rng, True
    rng.Cells(1).Select
    strDate = Format(Date, "dd-mm-yy") & " " & Format(Time, "h-mm-ss")
    ActiveWorkbook.SaveAs "Part of " & ThisWorkbook.Name _
                        & " " & strDate & ".xls"
    ActiveWorkbook.SendMail "ron@debruin.nl", _
                            "This is the Subject line"
    ActiveWorkbook.ChangeFileAccess xlReadOnly
    Kill ActiveWorkbook.FullName
    ActiveWorkbook.Close False
    Application.ScreenUpdating = True
End Sub

```

- You need to  **save the code**  by selecting it and then  **close the window**.

![](https://geekexcel.com/wp-content/uploads/2021/09/Save-the-Code-87-1024x849.png)<figcaption>Save the Code</figcaption>

- Again, you have to go to the  **Excel Spreadsheet** , and click on the  **Developer Tab**.
- You need to choose the  **Macros option**  in the Code section.

![Choose Macro option](https://geekexcel.com/wp-content/uploads/2021/09/Choose-Macro-option-11-1024x184.png)<figcaption>Choose Macro option</figcaption>

- Then, you have to make sure that your  **macro name is selected**  and click the  **Run ** button.

![](https://geekexcel.com/wp-content/uploads/2021/09/Run-the-Code-56.png)<figcaption>Run the Code</figcaption>

- Now, it will **unhide hidden rows and columns** in the **selection**.
- Finally, the **selection** is always on the **top of your sheet**.

## Closure

Here, we have explained the step-by-step procedure on how to **mail the selection using VBA** in Microsoft Excel. Make use of this. Please share your worthwhile  **feedback**  in the below  **comment**  section. To learn more, check out our website **[Geek Excel](https://geekexcel.com/)!!**

**Keep Reading:**

- **[How To Mail the Activeworkbook using VBA in Microsoft Excel?](https://geekexcel.com/how-to-mail-the-activeworkbook-using-vba-in-microsoft-excel/)**
- **[How to Send Bulk Emails From Excel VBA in One Click in Excel Office 365?](https://geekexcel.com/how-to-send-bulk-emails-from-excel-vba-in-one-click-in-excel-office-365/)**
- **[Extract Email Address from Text using Excel VBA](https://geekexcel.com/how-to-extract-email-address-from-text-using-excel-vba/)**
- **[Excel Formulas to Create Email Address From the Name ~ Quickly!!](https://geekexcel.com/excel-formulas-to-create-email-address-from-the-name/)**
- **[How to Validate Email Addresses in a Column or a Range of Cells in Excel?](https://geekexcel.com/how-to-validate-email-addresses-in-a-column-or-a-range-of-cells-in-excel/)**