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

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
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,214,981
Messages
6,122,566
Members
449,089
Latest member
Motoracer88

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