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.
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: