Hyperlink to email, attach file, add subject line and body

paun_shotts

New Member
Joined
Nov 4, 2021
Messages
38
Office Version
  1. 2013
Platform
  1. Windows
Hi,
I have a workbook for each of our suppliers, part of the workbook is a log of every order placed with the supplier, and the PO#, $ value, dates etc.
In Cell T1, I have a hyperlink that opens a new email in outlook, and auto fills in the receiver details.
What I want to do, is as the log is updated (a new order has been placed with the supplier) I need to email a pdf document with the email, to the supplier.

So I would like to automatically attached the pdf document to the email, the document is always stored in the same folder location, lets just call it "C:\Users\spotts\Documents\"
The document name will always start with "PO " and then will be the value of the last cell in column B, in the example the file name would be "PO ADP482.pdf"
I want the subject line to be "PO " and then the last value from column B, making it "PO ADP482"
Then I also want the body of the email to say:
"Hi,
Please find attached purchase order ADP482 for processing.
Thank you,"
I dont want to automatically send the email, just have the file attached, subject filled out, body filled out, and then have it on screen for me to review before pressing send.

Below is the minisheet, and thank you in advanced for your help.

Book1
ABCDEFGHIJKLMNOPQRSTU
1#PO## Items# B/O ItemsB/O ValueB/O Item #Order Date Order ValueDate first part recDays Taken (PART)Date Rec in FullDays Taken (FULL)MY Processing DaysNotesSUPPLIER Processing DaysShip DateDelivery DateDays TakenCONTACT NAMESCONTACT FOR POFREIGHT COMPANY
21ADP480967/07/2023$3,935.40014/07/202371411/07/202313/07/20232Salessales@seller.com.au
32ADP4818817/07/2023$4,213.80021/07/202340118/07/202321/07/20233
43ADP4825831/07/2023$3,558.30
5
6
7
8
9
10
11
Sheet1
Cells with Conditional Formatting
CellConditionCell FormatStop If True
J2:J3Other TypeColor scaleNO
O2:O11Other TypeColor scaleNO
O2:O11Other TypeColor scaleNO
R2:R11Other TypeColor scaleNO
O2:O11Other TypeColor scaleNO
J2:J11Other TypeColor scaleNO
L2:M11Other TypeColor scaleNO
J1Other TypeColor scaleNO
L1:M1Other TypeColor scaleNO
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
I have the below code, which seems to be working in the terms of creating the email, with recipients, subject and body, but not attaching the file. Yes, the file is present in the folder, I have checked 100 times.

The body of the email reads:
C:\Users\spotts\Documents\ File name is: PO ADP482.pdf

Below is a screenshot of the pdf file sitting in the documents folder:
picsss.JPG



VBA Code:
Sub send_single_email_with_chosen_attachment()

Dim outlookApp As Outlook.Application
Dim myMail As Outlook.MailItem
Dim Source_File As String
Dim lastRow As Long
Dim myPath As String

lastRow = Range("B1").End(xlDown).Row
myPath = "C:\Users\spotts\Documents\"

Set outlookApp = New Outlook.Application
Set myMail = outlookApp.CreateItem(olMailItem)



Source_File = "PO " & Range("B1").End(xlDown).Value & ".pdf"
myMail.To = "testing@gmail.com"
myMail.Subject = "Check Out my File!"
myMail.Body = myPath & " File name is: " & Source_File
  If Len(Dir(Source_File)) <> 0 Then 'IF THE FILE EXISTS THEN
    myMail.Attachments.Add Source_File
    End If
myMail.Display True
'myMail.send

End Sub
 
Upvote 0
Could it be done better with Application.FileSearch?
Im not sure on this one..
Please help someone.
 
Upvote 0
SOLVED - Was simply missing a "\" somewhere in the code. Cant remember exactly but issue is resolved.
 
Upvote 0

Forum statistics

Threads
1,215,149
Messages
6,123,311
Members
449,095
Latest member
Chestertim

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