Live-Forum - Die aktuellen Beiträge
Anzeige
Archiv - Navigation
1672to1676
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

Outlookprüfung schlägt fehl

Outlookprüfung schlägt fehl
13.02.2019 18:55:12
Bernd

Sub SendMail(ByVal strSubjekt As String, strAnhang As String, strText1 As String, strText2 As  _
String)
Dim objOutlook As Object, objMail As Object
Dim strSignatur As String, strMailtext As String
Set objOutlook = CreateObject("Outlook.Application") 'Outlook installiert?
If Not objOutlook Is Nothing Then
Else
MsgBox "Auf diesem System ist kein Outlook installiert!" & vbNewLine & "Die  _
erzeugte Datei mit dem hier installierten Mailsystem versenden", vbOKOnly, vbExclamation, "Kein Outlook!!!!"
Exit Sub
End If
Application.WindowState = xlMinimized
Set objMail = objOutlook.CreateItem(0)
strMailtext = "

" & _ strText1 & "
" & strText2 & "

" With objMail .GetInspector strSignatur = .HTMLBody .To = Sheets(2).[b144].Value .Subject = strSubjekt .attachments.Add strAnhang .HTMLBody = strMailtext & strSignatur .Display End With Set objOutlook = Nothing Set objMail = Nothing End Sub
Habe den Code aus dem Internet und an meine Bedürfnisse angepasst.
Das Problem ist die Abfrage ob Outlook installiert ist. Es wird bei nicht installiertem Outlook die Exit Sub ausgeführt ohne die MSGBox anzuzeigen.
Mit einem installierten Outlook wird ein ausgefülltes Mailfenster angezeigt.
Ich sehe den Fehler nicht......

5
Beiträge zum Forumthread
Beiträge zu diesem Forumthread

Betreff
Datum
Anwender
Anzeige
AW: Outlookprüfung schlägt fehl
13.02.2019 19:16:28
Sepp
Hallo Bernd,
Sub SendMail(ByVal strSubjekt As String, strAnhang As String, strText1 As String, strText2 As String)
  Dim objOutlook As Object, objMail As Object
  Dim strSignatur As String, strMailtext As String
    
  Set objOutlook = CreateObject("Outlook.Application") 'Outlook installiert? 
  If objOutlook Is Nothing Then
    MsgBox "Auf diesem System ist kein Outlook installiert!" & vbNewLine & _
      "Die erzeugte Datei mit dem hier installierten Mailsystem versenden", _
      vbOKOnly, vbExclamation, "Kein Outlook!!!!"
  Else
    Application.WindowState = xlMinimized
    Set objMail = objOutlook.CreateItem(0)
    strMailtext = vbLf & strText1 & strText2 & vbLf
    With objMail
      .GetInspector
      strSignatur = .HTMLBody
      .To = Sheets(2).[b144].Value
      .Subject = strSubjekt
      .attachments.Add strAnhang
      .HTMLBody = strMailtext & strSignatur
      .Display
    End With
  End If

  Set objMail = Nothing
  Set objOutlook = Nothing
End Sub

VBA/HTML-CodeConverter, AddIn für Office 2002-2016 - in VBA geschrieben von Lukas Mosimann. Projektbetreuung:RMH Software & Media

Code erstellt und getestet in Office 16 - mit VBAHTML 12.6.0


 ABCDEF
1Gruß Sepp
2
3

Anzeige
AW: Outlookprüfung schlägt fehl
13.02.2019 19:17:46
Nepumuk
Hallo Bernd,
hast du einen Errorhandler in der aufrufenden Prozedur? Zeig am besten mal den Code.
Gruß
Nepumuk
AW: Outlookprüfung schlägt fehl
13.02.2019 19:47:02
Bernd
Hallo Sepp, hallo Nepumuk,
@nepumuk: ja. Habe da ein On Error Resume Next.
Nach dem ich es auskommentiert habe bekomme ich bei SendMail() (Code so eingefügt wie Sepp ihn geschrieben hat) bei der ersten Set Anweisung einen Laufzeitfehler 429, Objekterstellung durch Activex-Komponente nicht möglich.
AW: Outlookprüfung schlägt fehl
13.02.2019 20:05:06
Nepumuk
Hallo Bernd,
dann in deiner Prozedur:
Sub SendMail(ByVal strSubjekt As String, strAnhang As String, _
        strText1 As String, strText2 As String)

    Dim objOutlook As Object, objMail As Object
    Dim strSignatur As String, strMailtext As String
    
    On Error Resume Next
    
    Set objOutlook = CreateObject("Outlook.Application") 'Outlook installiert?
    If objOutlook Is Nothing Then
        MsgBox "Auf diesem System ist kein Outlook installiert!" & vbLf & _
            "Die erzeugte Datei mit dem hier installierten Mailsystem versenden", _
            vbExclamation, "Kein Outlook!!!!"
    Else
        
        On Error GoTo 0
        
        Application.WindowState = xlMinimized
        Set objMail = objOutlook.CreateItem(0)
        
        strMailtext = strText1 & strText2
        
        With objMail
            .GetInspector
            strSignatur = .HTMLBody
            .To = Sheets(2).[b144].Value
            .Subject = strSubjekt
            .attachments.Add strAnhang
            .HTMLBody = strMailtext & strSignatur
            .Display
        End With
        
        Set objOutlook = Nothing
        Set objMail = Nothing
        
    End If
End Sub

On Error Resume Next benutze ich nur wenn ich einen Fehler erwarte den ich nicht abfangen kann wie z.B. dein CreateObject. Ansonsten kommt der nicht zum Einsatz.
Gruß
nepumuk
Anzeige
AW: Outlookprüfung schlägt fehl
13.02.2019 20:21:04
Bernd
Hallo nepumuk,
suuuuuper. Es funktioniert!!!!! Danke!!!

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige