Trouble with VBA email

bts73

New Member
Joined
Mar 14, 2019
Messages
3
Hello. I'm working on a project that requires a button click to launch an Outlook message box with a pre-filled template. I have had success with using the =hyperlink("mailto") function, but the contents of the message exceed 255 characters. I'm very novice at VBA script, and although I have tried a whole bunch of things I found online, but so far nothing has worked, at least without throwing errors at me that I personally can't debug.

For refernce here are the cell values I am using:

To: D30
CC: H31
Suject: D35
Body: F41 (I have concatenated the whole message here, but I would be interested in seeing how to combine text and cell values in VBA script: ex: "Hello", (A1) "Thanks")


Many thanks in advane for any advice you can offer.
 

Some videos you may like

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).

bts73

New Member
Joined
Mar 14, 2019
Messages
3
Tanksfe quick respose! I have actually tried a few things from that site, but am unable to manipulate this wthout erors, literally the script is stopping at the top line where the sub command sits. ...and because I am so novice to this, I don't know where to start from a debugging perspective.
 

DanteAmor

Well-known Member
Joined
Dec 3, 2018
Messages
12,618
Office Version
  1. 2007
Platform
  1. Windows
Try this:

Code:
Body: "Hello: " & Range("A1").Value & " Regards " & Range("C2").Value & " .Thanks"
 

Kenneth Hobson

Well-known Member
Joined
Feb 6, 2007
Messages
3,158
Office Version
  1. 365
Platform
  1. Windows
Click # icon on reply toolbar and paste code between code tags so we can debug.
 

bts73

New Member
Joined
Mar 14, 2019
Messages
3
Code:
[LEFT][COLOR=#000000][FONT=Courier]Sub CustomMailMessage()[/FONT][/COLOR][COLOR=#000000][FONT=Courier]
[/FONT][/COLOR][COLOR=#000000][FONT=Courier]Dim OutApp As Outlook.Application[/FONT][/COLOR][COLOR=#000000][FONT=Courier]
[/FONT][/COLOR][COLOR=#000000][FONT=Courier]Dim objOutlookMsg As Outlook.MailItem[/FONT][/COLOR][COLOR=#000000][FONT=Courier]
[/FONT][/COLOR][COLOR=#000000][FONT=Courier]Dim objOutlookRecip As Recipient[/FONT][/COLOR][COLOR=#000000][FONT=Courier]
[/FONT][/COLOR][COLOR=#000000][FONT=Courier]Dim Recipients As Recipients[/FONT][/COLOR][COLOR=#000000][FONT=Courier]
[/FONT][/COLOR][COLOR=#000000][FONT=Courier][/FONT][/COLOR][COLOR=#000000][FONT=Courier]
[/FONT][/COLOR][COLOR=#000000][FONT=Courier]  Set OutApp = CreateObject("Outlook.Application")[/FONT][/COLOR][COLOR=#000000][FONT=Courier]
[/FONT][/COLOR][COLOR=#000000][FONT=Courier]  Set objOutlookMsg = OutApp.CreateItem(olMailItem)[/FONT][/COLOR][COLOR=#000000][FONT=Courier]
[/FONT][/COLOR][COLOR=#000000][FONT=Courier][/FONT][/COLOR][COLOR=#000000][FONT=Courier]
[/FONT][/COLOR][COLOR=#000000][FONT=Courier]  Set Recipients = objOutlookMsg.Recipients[/FONT][/COLOR][COLOR=#000000][FONT=Courier]
[/FONT][/COLOR][COLOR=#000000][FONT=Courier]  Set objOutlookRecip = Recipients.Add("alias@domain.com")[/FONT][/COLOR][COLOR=#000000][FONT=Courier]
[/FONT][/COLOR][COLOR=#000000][FONT=Courier]  objOutlookRecip.Type = 1[/FONT][/COLOR][COLOR=#000000][FONT=Courier]
[/FONT][/COLOR][COLOR=#000000][FONT=Courier][/FONT][/COLOR][COLOR=#000000][FONT=Courier]
[/FONT][/COLOR][COLOR=#000000][FONT=Courier]  objOutlookMsg.SentOnBehalfOfName = "sales@domain.com"[/FONT][/COLOR][COLOR=#000000][FONT=Courier]
[/FONT][/COLOR][COLOR=#000000][FONT=Courier]  objOutlookMsg.Subject = "Testing this macro"[/FONT][/COLOR][COLOR=#000000][FONT=Courier]
[/FONT][/COLOR][COLOR=#000000][FONT=Courier]  objOutlookMsg.HTMLBody = "Testing this macro" & vbCrLf & vbCrLf[/FONT][/COLOR][COLOR=#000000][FONT=Courier]
[/FONT][/COLOR][COLOR=#000000][FONT=Courier]  'Resolve each Recipient's name.[/FONT][/COLOR][COLOR=#000000][FONT=Courier]
[/FONT][/COLOR][COLOR=#000000][FONT=Courier]  For Each objOutlookRecip In objOutlookMsg.Recipients[/FONT][/COLOR][COLOR=#000000][FONT=Courier]
[/FONT][/COLOR][COLOR=#000000][FONT=Courier]    objOutlookRecip.Resolve[/FONT][/COLOR][COLOR=#000000][FONT=Courier]
[/FONT][/COLOR][COLOR=#000000][FONT=Courier]  Next[/FONT][/COLOR][COLOR=#000000][FONT=Courier]
[/FONT][/COLOR][COLOR=#000000][FONT=Courier]  'objOutlookMsg.Send[/FONT][/COLOR][COLOR=#000000][FONT=Courier]
[/FONT][/COLOR][COLOR=#000000][FONT=Courier]  objOutlookMsg.Display[/FONT][/COLOR][COLOR=#000000][FONT=Courier]
[/FONT][/COLOR][COLOR=#000000][FONT=Courier][/FONT][/COLOR][COLOR=#000000][FONT=Courier]
[/FONT][/COLOR][COLOR=#000000][FONT=Courier]  Set OutApp = Nothing  [/FONT][/COLOR][COLOR=#000000][FONT=Courier]
[/FONT][/COLOR][COLOR=#000000][FONT=Courier]End Sub[/FONT][/COLOR][/LEFT]
 

Watch MrExcel Video

Forum statistics

Threads
1,127,352
Messages
5,624,173
Members
416,017
Latest member
moritz210

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
Top