Button to Email - and everything in between

NamssoB

Board Regular
Joined
Jul 8, 2005
Messages
76
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I have a project and I'm looking for some help. My first question is, will what I need actually be possible? Here is some info:

- I have a workbook with three t abs (Main, Data, Extras).
- In the Main worksheet, I have multiple named sections (Accounts, Matrix, & Payouts).
- I want to add a button to the worksheet that emails ONLY the Accounts named space as an Excel file attachment (NOT an image, or pasted into an email body). None of the other tabs should be included, nor should the other named areas.

My thought for the steps would be something like this:
- Copy the Named area to a new tab
- Delete the original tabs
- Save as a NEW Excel file (resulting in one workbook with one worksheet - with one named area (Accounts)
- Open Outlook object with appropriate To/From header information, including a brief body message
- Attach the new Workbook - and SEND

^ Can this even be done? if yes, I don't know how to make it work. I can make the button, and probably figure out the copy & past of the named Account area. But after that, I don't know how to remove the original tabs while preserving the code to do everything. I also don't know how to attach the existing (running) workbook into an Email and send it (using Outlook).
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Good news, it can be done and it's not immensely difficult either. Give me a few minutes, I'll write it for you
 
Upvote 0
Code:
    'Create new excel workbook
    Dim EmailBook as Workbook: Set EmailBook = Application.Workbooks.Add
  
    'Copy over appropriate range
    ThisWorkbook.Sheets("Main").Range("Accounts").Copy Destination:=EmailBook.Sheets(1).Range("A1")

    'Rename Sheet
    EmailBook.Sheets(1).Name = "Accounts"    

    'Save new book
    EmailBook.SaveAs (FILEPATH)

    'Prepare Email
    EmailBook.Application.Dialogs(xlDialogSendMail).Show

I am pretty sure that is as short as you can make it.

Hope this helps,
Chris
 
Upvote 0

Forum statistics

Threads
1,214,780
Messages
6,121,527
Members
449,037
Latest member
tmmotairi

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