每次单元格中的单元格值发生变化时,我都希望通过IBM / Lotus Notes向电子邮件地址发送电子邮件。
这是我正在使用的代码。请有人告诉我我哪里出错了吗?
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("M:M")) Is Nothing Then
If Target.Cells.Count < 3 Then
Dim iMsg As Object
Dim iConf As Object
Dim strbody As String
Dim fromAdr As String
Dim subject As String
Dim recip As String
Dim numSend As Integer
Dim Attachment1 As String
' Mail settings
Set iMsg = CreateObject("CDO.Message")
Set iConf = CreateObject("CDO.Configuration")
iConf.Load -1 ' CDO Source Defaults
Set Flds = iConf.Fields
' Mail fields
fromAdr = """food.specials@inbox.co.uk"
recip = """mark.smith@inbox.co.uk"
Debug.Print strbody
subject = "Orders fondsen"
strbody = strbody & "Hi," & vbNewLine & vbNewLine & _
"Please find the document..."
' Fields layout
strbody = strbody & vbNewLine & vbNewLine & "Text"
Debug.Print strbody
strbody = strbody & vbNewLine & vbNewLine & "Kind regards,"
' Location attachment
Attachment1 = "file-path"
' send mail
On Error GoTo handleError
With iMsg
Set .Configuration = iConf
.To = recip
.CC = ""
.From = fromAdr
.subject = subject
.TextBody = strbody
.Send
End With
numSend = numSend + 1
GoTo skipError
handleError:
numErr = numErr + 1
oFile.WriteLine "*** ERROR *** Email for account" & " not sent. Error: " & Err.Number & " " & Err.Description
skipError:
On Error GoTo 0
MsgBox "Total number of emails send: " & numSend & vbNewLine & "Total number of errors: " & numErr, vbOKOnly + vbInformation, "Operation finished"
GoTo endProgram
cancelProgram:
MsgBox "No emails have been sent.", vbOKOnly + vbExclamation, "Operation cancelled"
endProgram:
Application.Interactive = True
Set iMsg = Nothing
Set iConf = Nothing
Set dp = Nothing
End If
End If
End Sub
由于某种原因,电子邮件未被发送并转到错误处理程序。 然后我在这一行得到一个未定义的对象错误。
oFile.WriteLine "*** ERROR *** Email for account" & " not sent. Error: " & Err.Number & " " & Err.Description
由于