Sending email with attachment (formed from embedded excel) using VBA/Macro

gautam82grover

New Member
Joined
May 9, 2012
Messages
1
Hi,

I have been a regular visitor to this forum and had found solution to most of my questions. But the one mentioned, i could never find.
Here is my problem.

I need to use excel code, to mail certain recipients with an attachment. This attachment is an excel embedded in one of the worksheets (Lets say worksheet 7)

The code that i am using currently:

Sub Mail_Macro()
Dim counter As Integer
Dim LastMailRow As Integer
Dim Str As String

LastMailRow = Sheets("TMList").UsedRange.Rows.Count
counter = 0


For i = 3 To LastMailRow
If Sheets("TMList").Cells(i, 5).Value = Sheets("TMList").Cells(1, 2).Value And Sheets("TMList").Cells(i, 6).Value = "" Then
ESubject = Sheets("TMList").Cells(i, 3)
SendTo = Sheets("TMList").Cells(i, 2)
Set App = CreateObject("Outlook.Application")
Set Itm = App.CreateItem(0)
Str = Sheets("TMList").Cells(2, 11) & " " & Sheets("TMList").Cells(2, 8)
With Itm
.Subject = ESubject
.To = SendTo
.CC = "gautam82grover@hcl.com"
.Body = Str
'.Attachments = ???? 'I dont know how to do this
.send
End With
Set App = Nothing
Set Itm = Nothing
Sheets("TMList").Cells(i, 6).Value = "Mail sent"
counter = counter + 1
End If
Next
Sheets("TMList").Cells(3, 11).Value = counter
Set survey = Nothing
End Sub
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
You need the full path and name of the file you want to attach.
 
Upvote 0
In addition to what Norie suggested, you also need to write that line like this:

Code:
.Attachments.Add "filename.xls"
 
Upvote 0

Forum statistics

Threads
1,215,523
Messages
6,125,318
Members
449,218
Latest member
Excel Master

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