473,396 Members | 1,689 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,396 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 4271
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.