index > Visual Basic for Applications (VBA) > Emails via Excel

Emails via Excel


Hey Ladies and Gents,

I am a bit new to the world of visual basic so please be kind.

I have been set a mini-project here at work and need some assistance. What i am trying to achieve is for a user to click a command button in excel, opening up a new mail message in outlook. This new mail message will include filled areas in to, subject and main body with a hyperlink to the document in which they have just updated.

I have managed to produce the following code so far:

Sub Button1_Click()

Dim theApp, theNameSpace, theMailItem, myAttachment, MessageBody, subject

'create a new Outlook Application Object,
'direct it to the proper NameSpace,
'create a new Mail Item and set the attachments collection

Set theApp = CreateObject("Outlook.Application")
Set theNameSpace = theApp.GetNamespace("MAPI")
Set theMailItem = theApp.CreateItem(0)
theMailItem.Display
Set myAttachment = theMailItem.Attachments
MessageBody = "Please note the following file has now been updated {First Name Surname}"
subject = "subject information"

'add recipients to MailItem

theMailItem.Recipients.Add ("user@company.co.uk")
theMailItem.subject = subject
theMailItem.Body = MessageBody

End Sub

I need some help with the body format e.g. paragraphs and what/how do i need to implement a hyperlink in the body of the email

Hopefully some of you can help

Thanks

Richard

Randall155

If your default Outlook setting is to compose new emails as HTML, I think you can just send HTML-formatted text to the MessageBody like this:

Dim strMyMsgBody As String
strMyMsgBody = "Dear Sirs,<br>"
strMyMsgBody = strMyMsgBody & "<a href=" & Chr(34) & "mailto:nobody@nobody.com" & Chr(34) & ">Send me mail.</a>"
theMailItem.Body = strMyMsgBody

Chr(34) is the double-quotation mark, so you need to include it as in the above example on either side of anything that would normally be in quotes in HTML.

Does this help?




a little trolley is a dangerous thing for example you could trip over it
duck thing

Hey duck thing,

Thank you for you help so far.

I am bit of a newbie at all this so would it be possible for you to show me exactly where i would insert this into my coding?

Then i shall give this a test run and keep you posted on my results

Thanks

Rich

Randall155

Excel MVP Ron de Bruin has a lot of information about emailing from Excel on his web site. You might get what you need all at once, rather than a drip at a time here:

http://www.rondebruin.nl/sendmail.htm

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Tutorials and Custom Solutions
http://PeltierTech.com
_______



MS Excel MVP
Jon Peltier

I have taken a look at the link which you provided but dont feel any of the info on that site will help (please correct me if i am wrong). Like i said before i am totally new to this and feel i have done quite well so far. Please could someone assist me or show me how i could make up the body of the email using HTML as suggested by 'duck thing'

Please help me

Rich

Randall155
reply 5

You can use google to search for other answers

 

More Articles

• Wildcards In Access
• ActiveDocument.FollowHyperlink acts funny
• provider cannot found with MDAC 2.8 Win XP sp2
• Adding an Outlook Feature
• Using of APC.IDE.PreventShow property
• Querying ActiveDirectory with VBA in Excel
• excel vba
• EOF or BOF error
• Setting the correct row height for merged cells in Exel
• Picture Question
Welcome to Bokebb   New Update   Joins the collection  
 

New Articles

• excel hyperlink - top/bottom of screen
• Exporting a table from an Access File to
• variable formatting in subform rows
• Add code in control image in time of exe
• ScrollBars for Userforms
• Runtime error '-2147467259(80004005)';
• Linking Outlook to Excel
• VBA eBook
• menu tiems for OutputToText, OutputToExc
• Distributing a Macro across an organizat
• Access "ldb"
• Text file search, return data from line
• Program aborts only when run with Access
• VB in word 2000 / form built into a temp
• Error 3251 using ADO & VBA to drop a

Hot Articles

• Excel VBA
• Output excel file to PDF format
• Using the API of Visio to open a Custom
• macro script?
• Missing files
• A Simple question about vba editor and v
• How to refer to an object by the tab index
• passing data from a form to a module
• use Active directory to find ip address
• vba5.0 doesn't work on dual core compute
• HTTP request - simple problem
• Word 2000 section page numbering bug? An
• About Jet WorkSpace
• How to write a 'Find function' code in V
• Access Developer Extensions

Recommend Articles

• How do you test a user's input for alpha
• PowerPoint, WORD, and Macros
• Controls in a Word Document
• Deleting tabs when a cell is emptied
• Excel, Forms, and Charts
• Please, How change a class name in VBA E
• how to add CheckBox?
• VSTA support
• how to convert excel to tiff file using
• help me
• VBA text box! I'm completely lost...
• Refreshing table list in Access
• Dialog Box, Searching for keywords in an
• DoCmd (1312)
• EOF or BOF error