Email button with file path

Mc2388

New Member
Joined
Apr 2, 2018
Messages
4
Hi all,

I have tried using the below code to add an Active X button to automatically send an email. I have gotten this to work but wanted to add some static text to the email body along with the file path of the current workbook and was wondering if someone could help? If possible also I’d like to have the current file name quoted in the subject line?

Any help and suggestions greatly appreciated!

Private Sub CommandButton1_Click()
Dim xOutApp As Object
Dim xOutMail As Object
Dim xMailBody As String
On Error Resume Next
Set xOutApp = CreateObject("Outlook.Application")
Set xOutMail = xOutApp.CreateItem(0)
xMailBody = "Body content" & vbNewLine & vbNewLine & _
"This is line 1" & vbNewLine & _
"This is line 2"
On Error Resume Next
With xOutMail
.To = "Email Address"
.CC = ""
.BCC = ""
.Subject = "Test email send by button clicking"
.Body = xMailBody
.Display
End With
On Error GoTo 0
Set xOutMail = Nothing
Set xOutApp = Nothing
End Sub
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Hi tcaslv,

Thanks for the response, I had seen your post but had hoped to include the current workbooks filepath without having to manually amend it every time I move the workbook itself. I also wanted to display the email before sending, to allow for an ad hoc message.

Any suggestions again appreciated!
 
Upvote 0
If you refer back to the code I pasted, there is a comment section on the bottom after the string. I made the mistake in the begining and didnt know those were comments my self. But anything with a " ' " before the text is your comments and usually let you know some options you have for a particular string.

Code:
.Send '.Send to skip preview .Display to preview email

If you see at the begining of the string, the ".send" with out the quotes is your option for the string. If you just want to view the email before it sends out, change ".send" to ".display" again with out the quotes. I know there is a code for placing the filepath where the workbook is currently at, but last time I messed with it, it didnt produce good results. Im still green to the code, but the above suggestion should at least help on your other issue.
 
Upvote 0
Thanks tcaslv,
Any ideas about adding a filepath that will stay updated as file may be moved between folders? Also if possible adding the file name to subject line?

Cheers!
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,176
Members
453,021
Latest member
Justyna P

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