How to email to a email address inside a textbox

Pookiemeister

Well-known Member
Joined
Jan 6, 2012
Messages
626
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
I have button on my form that I would like use to open outlook to send an email to the person inside the textbox which is labeled "Email", as a start. Thank you.
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Thank you for the quick response but I noticed this doesn't work on older versions of Outlook because I am running MS Office 2010 at home but MS Office 365 at work. When I run this code on my home computer, I get the following error message: Error Message "This action is not supported while an older version of Outlook is running." How can I get this to work in Office 2010 on both versions. Thank you again.

VBA Code:
Dim olApp As Outlook.Application
   Dim MI As Outlook.MailItem
   Dim sPath, sFileName, CurrentTime, Salutation As String
   Dim sFileLocation As String
   Dim wbAnswer, EmilAnswer As Integer

   CurrentTime = Format(Now, "hh:mm:ss")
    If CurrentTime > "05:00:00" And CurrentTime < "12:00:59" Then
        Salutation = "Good morning "
    ElseIf CurrentTime > "12:01:00" And CurrentTime < "16:59:59" Then
        Salutation = "Good afternoon "
    ElseIf CurrentTime > "17:00:00" And CurrentTime < "20:59:59" Then
        Salutation = "Good evening "
    Else
        Salutation = "Dear "
    End If

        Set olApp = New Outlook.Application
        Set MI = olApp.CreateItem(olMailItem)

      DoCmd.SendObject

        With MI
            .To = EmailContact1
            .CC = ""
            .Subject = "Purchase Order Number: " & PONumber
            .Body = Salutation & FirstName1 & "," & vbNewLine & vbNewLine
            .Display
        End With
        Set MI = Nothing
        Set olApp = Nothing
 
Last edited:
Upvote 0
Here you go

VBA Code:
Sub jec()
 Dim Salutation as String
 Select Case Time
    Case Is < "12:00:59": Salutation = "Good morning "
    Case Is < "16:59:59": Salutation = "Good afternoon "
    Case Is < "20:59:59": Salutation = "Good evening "
    Case Else: Salutation = "Dear "
 End Select
 With CreateObject("outlook.application").createitem(0)
    .To = "test@gmail.com"
    .Subject = "test"
    .body = Salutation
    .display
 End With
End Sub
 
Upvote 0
@JEC

Will this method also work with newer versions of Outlook, like in Office 365? Thank you.
 
Upvote 0
Next question which I just thought about, what if the user uses outlook online?
 
Upvote 0
That would not be possible to automate with this object class.
But if the user also has outlook desktop on his/her pc, it should still work.
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,207
Members
452,618
Latest member
Tam84

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