Live-Forum - Die aktuellen Beiträge
Anzeige
Archiv - Navigation
1260to1264
Aktuelles Verzeichnis
Verzeichnis Index
Übersicht Verzeichnisse
Vorheriger Thread
Rückwärts Blättern
Nächster Thread
Vorwärts blättern
Anzeige
HERBERS
Excel-Forum (Archiv)
20+ Jahre Excel-Kompetenz: Von Anwendern, für Anwender
Inhaltsverzeichnis

Email aus Excel

Email aus Excel
Goeran
Hallo,
ich habe leider keine Antwort auf meine Frage in alten Forumbeiträgn gefunden. In Excel 2003
hatte ich eine Funktion, mit der ich sehr einfach Emails versenden konnte (ohne weiteres Bestätigen).
Dafuer musste die CDO.dll installiert sein. Ich habe nun Excel 2007 und verstehe es so, dass man
nicht mehr mit der CDO.dll arbeiten kann. Alle Lösungen, die ich bisher im Forum gefunden habe
haben jedoch ein Outlook Fenster geöffnet welches man bestätgien muss.
Gibt es keine Möglichkeit, dies wie in Excel 2003 einfach zu senden ohne weitere Buttons betätigen
zu muessen ? Anbei der Code, den ich immer genutzt habe. Vielen Dank für die Hilfe.
Goeran
Option Explicit
Dim b As Boolean
Private Sub Worksheet_Change(ByVal Target As Range)
If Cells(1, 1).Value = "1" Then
sendmail Cells(4, 4).Value, Cells(4, 5).Value, Cells(4, 2).Value, Cells(4, 3).Value, _
_
Cells(4, 6).Value
Cells(1, 1).Value = "0"
End If
End Sub
Sub sendmail(fromWho, toWho, Subject, Body, smtphost)
On Error GoTo fehler
Dim objCDO
Dim iConf
Dim Flds
Const cdoSendUsingPort = 2
Set objCDO = New CDO.Message
Set iConf = New CDO.Configuration
Set Flds = iConf.Fields
With Flds
.Item(cdoSendUsingMethod) = cdoSendUsingPort
.Item(cdoSMTPServer) = smtphost
.Item(cdoSMTPServerPort) = 25
.Item(cdoSMTPconnectiontimeout) = 10
.Item(cdoSMTPAuthenticate) = cdoBasic
.Item(cdoSendUserName) = "info@test.de"
.Item(cdoSendPassword) = "12345"
.Update
End With
Set objCDO.Configuration = iConf
objCDO.From = fromWho
objCDO.To = toWho
objCDO.Subject = Subject
objCDO.TextBody = Body
objCDO.Send
Exit Sub
fehler:
End Sub

1
Beitrag zum Forumthread
Beitrag zu diesem Forumthread

Betreff
Benutzer
Anzeige
AW: Email aus Excel
11.05.2012 23:24:38
Josef

Hallo Gorean,
sich funktioniert CDO unter Office 2007.
Ich würde das so lösen.
' **********************************************************************
' Modul: Tabelle1 Typ: Element der Mappe(Sheet, Workbook, ...)
' **********************************************************************

Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)
  On Error GoTo ErrExit
  If Cells(1, 1).Value = "1" Then
    Application.EnableEvents = False
    sendMail_CDO Cells(4, 4).Value, Cells(4, 5).Value, Cells(4, 2).Value, Cells(4, 3).Value
    Cells(1, 1).Value = "0"
  End If
  
  ErrExit:
  Application.EnableEvents = True
End Sub


' **********************************************************************
' Modul: Modul1 Typ: Allgemeines Modul
' **********************************************************************

Option Explicit

'Don't Change!
Private Const cstrSchema As String = "http://schemas.microsoft.com/cdo/configuration/"
'End Don't Change!

Private Const cstrSMTPServer As String = "mail.provider.com" 'Fill in your SMTP-Server!
Private Const cstrUSERNAME As String = "Your Username" 'Fill in your Mailaccount Username
Private Const cstrPASSWORD As String = "Your Password" 'Fill in your Mailaccount Password
Private Const cstrADDRESS As String = "name@domain.com" 'Your Mail-Address

Sub sendMail_CDO(SenderName, Recever, Subject, Body)
  Dim objMsg As Object, objConf As Object
  Dim vntFields As Variant
  
  On Error GoTo ErrExit
  
  Set objMsg = CreateObject("CDO.Message")
  Set objConf = CreateObject("CDO.Configuration")
  
  objConf.Load -1 ' CDO Source Defaults
  
  Set vntFields = objConf.Fields
  
  With vntFields
    .Item(cstrSchema & "sendusing") = 2
    .Item(cstrSchema & "smtpserver") = cstrSMTPServer
    .Item(cstrSchema & "smtpserverport") = 25
    
    'When you also get the Authentication Required Error you can add this three lines.
    ' .Item(cstrSchema & "smtpauthenticate") = 1
    ' .Item(cstrSchema & "sendusername") = cstrUSERNAME
    ' .Item(cstrSchema & "sendpassword") = cstrPASSWORD
    
    .Update
  End With
  
  With objMsg
    Set .Configuration = objConf
    .To = Recever
    .CC = ""
    .BCC = ""
    .From = SenderName
    .Subject = Subject
    .TextBody = Body
    
    
    ' ' Set importance or Priority to high
    ' .Fields("urn:schemas:httpmail:importance") = 2
    ' .Fields("urn:schemas:mailheader:X-Priority") = 1
    '
    ' ' Request read receipt
    ' .Fields("urn:schemas:mailheader:return-receipt-to") = cstrADDRESS
    ' .Fields("urn:schemas:mailheader:disposition-notification-to") = cstrADDRESS
    '
    ' ' Update fields
    ' .Fields.Update
    
    .Send
  End With
  
  
  ErrExit:
  
  If Err.Number <> 0 Then
    MsgBox "Fehler:" & vbTab & Err.Number & vbLf & vbLf & Err.Description & _
      vbLf & vbLf, vbExclamation, "Fehler"
  End If
  
  Set objConf = Nothing
  Set objMsg = Nothing
End Sub



« Gruß Sepp »

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige