473,320 Members | 1,940 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

In Outlook, create a VBA Script for sending email

Hello,

A simple request I am sure, but I am unclear of the procedure. I have limited experience with VB, so here goes:

I am trying to create a simple VB application that will bring up a form box with a TextInput for an email address and a SEND (caption) button only.

The function of this application will, when the SEND button is clicked Outlook 2010 will:

1. Open and populate the To: field with the email address from the Text Box input.
2. Attach a file rom a specified folder (same with all outgoing emails)
3. Close Outlook

Basically our secretary should have this Form Input box on her desktop, type an email address and hit SEND.

Any detailed assistance is appreciated.
Jul 14 '14 #1

✓ answered by Luuk

In Outlook press ALT+F10

Create a new 'UserForm', and add a Textbox, and a Button on it.

Give the butten a correct name, and doubleclick it.

enter next code:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Send_Click()
  2.     Dim msg As Outlook.MailItem
  3.     Set msg = Application.CreateItem(olMailItem)
  4.     msg.Subject = "Hello World!"
  5.     msg.To = Me.TextBox1.Value
  6.     msg.Attachments.Add "c:\temp\test.pdf", olByValue, 2, "test"
  7.     UserForm1.Hide
  8.     msg.Send
  9.     Set msg = Nothing
  10. End Sub
  11.  
  12.  

after that, rightclick on 'Modules', and create a module with next code:
Expand|Select|Wrap|Line Numbers
  1. Sub mailthis()
  2.     UserForm1.Show
  3. End Sub
  4.  
save everything,

a shotcurt with the following command should start tha macro (providing the names are equal):
Expand|Select|Wrap|Line Numbers
  1. "C:\Program Files\Microsoft Office 15\root\office15\outlook.exe" /autorun "Project1.mailthis"

5 4266
Luuk
1,047 Expert 1GB
What about the 'Right Click'/'Send to'/'Mail recipient'?

If your secretary is not smart enough to do that, your secretary should get a basic computer course.

This will benefit you, and your company.
Jul 14 '14 #2
An option, yes...but there is a reason for the method I have inquired about!
Jul 14 '14 #3
Luuk
1,047 Expert 1GB
In Outlook press ALT+F10

Create a new 'UserForm', and add a Textbox, and a Button on it.

Give the butten a correct name, and doubleclick it.

enter next code:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Send_Click()
  2.     Dim msg As Outlook.MailItem
  3.     Set msg = Application.CreateItem(olMailItem)
  4.     msg.Subject = "Hello World!"
  5.     msg.To = Me.TextBox1.Value
  6.     msg.Attachments.Add "c:\temp\test.pdf", olByValue, 2, "test"
  7.     UserForm1.Hide
  8.     msg.Send
  9.     Set msg = Nothing
  10. End Sub
  11.  
  12.  

after that, rightclick on 'Modules', and create a module with next code:
Expand|Select|Wrap|Line Numbers
  1. Sub mailthis()
  2.     UserForm1.Show
  3. End Sub
  4.  
save everything,

a shotcurt with the following command should start tha macro (providing the names are equal):
Expand|Select|Wrap|Line Numbers
  1. "C:\Program Files\Microsoft Office 15\root\office15\outlook.exe" /autorun "Project1.mailthis"
Jul 14 '14 #4
Perfect, thank you Luuk, that does work! Keeping the form open is perfect, however the line for closing Outlook upon sending is what I also need.

I played with the following, but unable to mesh:

objMail.Send

objOutlook.Quit
Set objMail = Nothing
Set objOutlook = Nothing
Jul 14 '14 #5
Luuk
1,047 Expert 1GB
Expand|Select|Wrap|Line Numbers
  1. Application.Quit
will close Outlook,
but only if the mail is already send,
otherwise some notification is show about Outlook being busy sending a mail.....
Jul 15 '14 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

13
by: joe215 | last post by:
I want my users to send emails from a Windows app that I am developing in Visual Basic.NET 2003. I found a good example of sending email to a SMTP server using the SmtpMail class. However, using...
17
by: Bonj | last post by:
Right guys. (I would like a solution to this in VB6 as this is what our needy app is written in, but any solutions that involve .NET would be much appreciated likewise as I could instantiate...
8
by: Frank | last post by:
I think I've confused myself completely here :-) I have used System.Web.Mail, but am not sure if this works with Exchange Server 5.5. I asked the client if they're email server supported SMTP, and...
2
by: =?Utf-8?B?QXJuZSBCZXJ1bGRzZW4=?= | last post by:
In my vb.net 2005 app ...I'm sending email via Outlook 2003. How do I eliminate that annoying outlook box when sending the email. Thanks
7
by: Paridevi | last post by:
Hai , i want to send email in .Net Using OutLook Express,My Project is Web Application using vb.Net 2003 with SQL Server 2000.I have searched a lot in Google, but ican't get any...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.