Need help in Macro for 2 tasks

freelancerchn

New Member
Joined
Sep 19, 2014
Messages
6
Good day all!

First, I must admit that this website has helped me in many instances for my no-vice coding skills.
Now, I am in a fix. I am sincerely looking out for help from fellow members in performing the following tasks.
1. Copy a range of cells from active sheet and put that in body of email.
2. Copy a range of cells in another sheet in the active workbook and put that as an attachment.
3. Now both the above has to be done in the same email.
The code I currently use for first situation is below;
=====
Sub Lo()

' Select the range of cells on the active worksheet.

Range("E65536").End(xlUp).Offset(1, 0).Select
Range(ActiveCell, ActiveCell.Offset(0, 10)).Select
Range(Selection, Selection.End(xlUp)).Select
Range(Selection, Selection.End(xlUp)).Select
Range(Selection, Selection.End(xlUp)).Select
Range(Selection, Selection.End(xlUp)).Select

' Show the envelope on the ActiveWorkbook.

ActiveWorkbook.EnvelopeVisible = True

With ActiveSheet.MailEnvelope

.Introduction = "Hi Team"
.Item.To = "abc@abc.com"
.Item.CC = ""
.Item.Subject = "Subject line"

End With
=====
It would really help if somebody can help me consolidate the code. If this works out I can save a lot of time in reports.
Thanks in advance for any assistance guys!
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
I got this resolved with the below code. I copied the contents to another workbook and then attached it to the existing email.

Code:
Sub Send_Range1()

Sheets("123").Select
Range("A4:Z4").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy

MsgBox ("123 is ready to be copied.")

Workbooks.Open Filename:="location of file"
Sheets("Sheet1").Select
Cells.Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False

Application.CutCopyMode = False
Range("A1").Select
Application.CommandBars("Office Clipboard").Visible = False
ActiveWorkbook.Save
MsgBox ("123 is now copied,saved and closed.")
ActiveWorkbook.Close
Sheets("456").Select

Range("B65536").End(xlUp).Offset(1, 0).Select
Range(ActiveCell, ActiveCell.Offset(0, 8)).Select
Range(Selection, Selection.End(xlUp)).Select
Range(Selection, Selection.End(xlUp)).Select

ActiveWorkbook.EnvelopeVisible = True

With ActiveSheet.MailEnvelope

.Introduction = "Hi " 
.Item.To = ""
.Item.CC = ""
.Item.Subject = ""
.Item.Attachments.Add ("location of file")

MsgBox ("The email will be sent now. Please ensure there is only one attachment and click **Send this selection** button now.")

End With
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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