Help with sending email via Ouloook 365 (OWA) in Excel

rv02s

New Member
Joined
Jun 21, 2014
Messages
21
Hi all

I have the following code in my Excel worksheet. This code successfully send out email to our customers when if the criteria is true. I have tested this at home and it works perfectly as I use Outlook at home. However when I take this code to work I couldn't get this working as at work we use Outlook 365 and we use web Outlook, OWA. Every time I run this code it tries to setup Outlook on the PC for me which we are not allowed to do.

is there a setting I can specify to use OWA as I don't think I am allowed to install outlook at work. I need this help urgently as I have to present this code to my boss.

Any help is much appreciate it.
Code:
 Private Sub CommandButton1_Click()
 Dim i As Long


 With Sheets("Sheet1")
 ' if 30 days have passed and customer has spent more than 1000 and want to receive email
 For i = 5 To .Range("A" & Rows.Count).End(xlUp).Row
 If DateDiff("d", .Cells(i, 10).Value, Now) >= 30 And .Cells(i, 11).Value = "y" And .Cells(i, 8).Value >= 1000 Then
 If DateDiff("d", .Cells(i, 9).Value, Now) >= 30 Then
 'send email using Outlook
 With CreateObject("Outlook.Application").CreateItem(0)
 .To = Sheets("Sheet1").Cells(i, 2).Value
 .CC = "ggg@hotmail.com"
 .Subject = "30 Days has passed since your last purchase."
 .Body = "Dear " & Cells(i, 1).Value & Cells(i, 2).Value & vbNewLine & vbNewLine & _
 "It has been a while since you have visited the Department ......"
 .Display ' Change to .Send to skip the display

 End With
 .Cells(i, 10).Value = Format(Now, "dd/mm/yyyy")
 End If
 ElseIf DateDiff("d", .Cells(i, 10).Value, Now) >= 15 And .Cells(i, 11).Value = "y" And .Cells(i, 8).Value >= 500 And .Cells(i, 8).Value < 1000 Then
 If DateDiff("d", .Cells(i, 9).Value, Now) >= 15 Then
 'send email using Outlook
 With CreateObject("Outlook.Application").CreateItem(0)
 .To = Sheets("Sheet1").Cells(i, 2).Value
 .CC = "ggg@hotmail.com"
 .Subject = "15 Days has passed since your last purchase."
 .Body = "Hi " & Cells(i, 1).Value & Cells(i, 2).Value & vbNewLine & vbNewLine & _
 "Come and buy more things!"
 .Display ' Change to .Send to skip the display

 End With
 .Cells(i, 10).Value = Format(Now, "dd/mm/yyyy")

 End If
 '.Cells(i, 9).Value = Format(Now, "dd/mm/yyyy")
 End If

 Next i
 End With
 End Sub
 
Last edited by a moderator:

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Will it be possible to send me the code or example of this in my code above as I am new to vba
thanks
 
Upvote 0
Upvote 0
I tried the example and it works but when I try to do this with my work email it sends the server could not authenticate. At work we are using Office365, and I think the smtp server is smtp.office365.com but I cant not get it working. do I have to be running this when I am in the office or can I try it from home. the gmail example worked fine but the office 365 does not run
 
Upvote 0

Forum statistics

Threads
1,214,973
Messages
6,122,534
Members
449,088
Latest member
RandomExceller01

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