Hi,
I have a mail macro that automatically sends email based on a cell value in Excel.
So what this is supposed to do is auto mail when cell C2 is larger than 0. This is working as it should.
The problem here is that the values are gathered with formulas, "=COUNTIF(Utleveranser.Data!B:B, 1)". So the data in cell C2 isn't inserted manually.
When the data is inserted manually, the automail works. But if the value gets inserted through the formula, the mail function doesn't work.
Any ideas?
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count > 1 Then Exit Sub
If Not Application.Intersect(Range("C2"), Target) Is Nothing Then
If IsNumeric(Target.Value) And Target.Value > 0 Then
Call Indiska
End If
End If
Public Sub Indiska()
Dim OutApp As Object
Dim OutMail As Object
Dim strbody As String
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
strbody = "Indiska"
On Error Resume Next
With OutMail
.To = ""
.CC = ""
.BCC = ""
.Subject = "Subject"
.Body = strbody
.Send
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
End Sub
I have a mail macro that automatically sends email based on a cell value in Excel.
So what this is supposed to do is auto mail when cell C2 is larger than 0. This is working as it should.
The problem here is that the values are gathered with formulas, "=COUNTIF(Utleveranser.Data!B:B, 1)". So the data in cell C2 isn't inserted manually.
When the data is inserted manually, the automail works. But if the value gets inserted through the formula, the mail function doesn't work.
Any ideas?
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count > 1 Then Exit Sub
If Not Application.Intersect(Range("C2"), Target) Is Nothing Then
If IsNumeric(Target.Value) And Target.Value > 0 Then
Call Indiska
End If
End If
Public Sub Indiska()
Dim OutApp As Object
Dim OutMail As Object
Dim strbody As String
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
strbody = "Indiska"
On Error Resume Next
With OutMail
.To = ""
.CC = ""
.BCC = ""
.Subject = "Subject"
.Body = strbody
.Send
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
End Sub