PDA

View Full Version : Macro to email file location



Sir Humphrey
01-30-2013, 11:21 AM
Hi
I have a file that I email a hyperlink to every hour (its on a shared drive), is there a way to use VBA to send an email which would put the file location in the body of the email? I already have the code

Sub Send_Email_Using_VBA()
Dim Email_Subject, Email_Send_From, Email_Send_To, Email_Body As String
Dim Mail_Object, Mail_Single As Variant
Email_Subject = "File"
Email_Send_From = "me@hotmail.com"
Email_Send_To = "recipient@hotmail.com"
Email_Body = "Here is the link to your file H:\Folder\Week 1\Monday.xslm"
On Error GoTo debugs
Set Mail_Object = CreateObject("Outlook.Application")
Set Mail_Single = Mail_Object.CreateItem(0)
With Mail_Single
.Subject = Email_Subject
.To = Email_Send_To
.cc = Email_Cc
.BCC = Email_Bcc
.Body = Email_Body
.send
End With
debugs:
If Err.Description <> "" Then MsgBox Err.Description
End Sub But I cannot find a way to change the H:\Folder\Week 1\Monday.xslm part to whatever that day's file happens to be called?

Sir Humphrey
01-30-2013, 02:33 PM
Found a solution, the code to get the file name is ThisWorkbook.FullName so the macro would become

Sub Send_Email_Using_VBA()
Dim Email_Subject, Email_Send_From, Email_Send_To, Email_Body As String
Dim Mail_Object, Mail_Single As Variant
Email_Subject = "File"
Email_Send_From = "me@hotmail.com"
Email_Send_To = "recipient@hotmail.com"
Email_Body = "Here is the link to your file. " & ThisWorkbook.FullName
On Error Goto debugs
Set Mail_Object = CreateObject("Outlook.Application")
Set Mail_Single = Mail_Object.CreateItem(0)
With Mail_Single
.Subject = Email_Subject
.To = Email_Send_To
.cc = Email_Cc
.BCC = Email_Bcc
.Body = Email_Body
.send
End With
debugs:
If Err.Description <> "" Then MsgBox Err.Description
End Sub