Making Email and attachments dynamic

Jstns

New Member
Joined
Feb 13, 2017
Messages
1
Dear all,

I am experiencing difficulties with Excel VBA! Below is what I have typed in VBA. I want to reference the file name, body, subject and attachment to a cell if possible. Please help!

Sub Print_en_save()


Dim saveCell As Range
Dim savepathCell As Range


Set saveCell = ActiveSheet.Range("T17")
SaveAs = saveCell.Value

Set savepathCell = ActiveSheet.Range("T16")
savepath = savepathCell.Value


' Save as PDF
ChDir savepath
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
SaveAs & ".pdf", Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
:=False


Dim OutLookApp As Object
Dim OutLookMailItem As Object
Dim myAttachments As Object


Set OutLookApp = CreateObject("Outlook.application")
Set OutLookMailItem = OutLookApp.CreateItem(0)
Set myAttachments = OutLookMailItem.Attachments


With OutLookMailItem
.To = ("T8")
.Subject = ("T19")
.Body = ("T20")
myAttachments ("T21")
.Send


End With


End Sub
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.

Forum statistics

Threads
1,223,903
Messages
6,175,289
Members
452,631
Latest member
a_potato

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