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

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
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,223,230
Messages
6,170,883
Members
452,364
Latest member
springate

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