email using user form

buzz71023

Active Member
Joined
May 29, 2011
Messages
295
Office Version
  1. 2016
Platform
  1. Windows
I have a userform with three 2 textboxes, textbox 1 = subject, textbox 2 = body of email and a command button to send the email. I want users to be able to send an email to my email (myemail@email.com) (for reporting problems with workbook).

If I have to I don't have to use a userform. I can create another worksheet to have the info put in ranges and do it that way... If thats the way I have to do it range c2 = subject, c5 = body of email. If email address is need in a range I would put it in c1.
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Try something like this...

Code:
[font=Verdana][color=darkblue]Option[/color] [color=darkblue]Explicit[/color]

[color=darkblue]Private[/color] [color=darkblue]Sub[/color] CommandButton1_Click()
    [color=darkblue]Dim[/color] OutlookApp [color=darkblue]As[/color] Outlook.Application
    [color=darkblue]Dim[/color] MItem [color=darkblue]As[/color] Outlook.MailItem
    [color=darkblue]Set[/color] OutlookApp = [color=darkblue]New[/color] Outlook.Application
    [color=darkblue]Set[/color] MItem = OutlookApp.CreateItem(olMailItem)
    [color=darkblue]With[/color] MItem
        .To = "myemail@email.com"
        .Subject = Me.TextBox1.Text
        .Body = Me.TextBox2.Text
        [color=green]'.Send[/color]
        .Save [COLOR="Green"]'to drafts folder[/COLOR]
    [color=darkblue]End[/color] [color=darkblue]With[/color]
    [COLOR="Green"]'Unload Me[/COLOR]
[color=darkblue]End[/color] [color=darkblue]Sub[/color]
[/font]
 
Upvote 0
I forgot to mention that you'll need to set a reference...

Tools > References > and select Microsoft Outlook Object Library
 
Upvote 0
Nothing seems to be happening when I press the send button. Not a debug error or anything. I copied and pasted the code and then went into tools and select Microsoft Outlook 14.0 Object Library (I have Office 2010 if that matters). This will be ran on Office 2003 until just after the first of the year.

I have double checked everything and it is all in the right place.
 
Upvote 0
Did you place the code in the code module for the UserForm?

Did you change the names of the controls (CommandButton1, TextBox1, and TexBox2), accordingly?

As it stands, the email is saved in the drafts folder. Have you checked to see whether the email is in fact in the drafts folder?
 
Upvote 0
thats where it is at.. sorry i didnt look in the drafts folder... is there anyway to get it to send automatically? could i set up a rule in outlook or would i have to do a macro? i am trying to make it as few steps as possible for some of the user bc some are almost computer illiterate. thanks for the help so far also, it is a huge help.
 
Upvote 0
Or is that what it does? Sorry, just a little confused to why it is in my drafts. Like its a email im trying to send instead of receiving it. Guess ill need to test it once its on the server.
 
Upvote 0
For testing purposes, it is being saved in the drafts folder. To send it, delete the following line...

Code:
       .Save 'to drafts folder

...and replace...

Code:
        '.Send

with

Code:
        .Send
 
Upvote 0

Forum statistics

Threads
1,214,583
Messages
6,120,377
Members
448,955
Latest member
BatCoder

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