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

Outlook

Outlook
23.03.2022 16:54:44
Alex
Hallo Leute
Ich habe im Netz folgendes Beispiel herungergeladen:


Private Sub DisplaySenderDetails()
Dim Explorer As Outlook.Explorer
Dim CurrentItem As Object
Dim Sender As Outlook.AddressEntry
Dim Contact As Outlook.ContactItem
Set Explorer = Application.ActiveExplorer 'Hier wird ein Fehler ausgelöst
' Check whether any item is selected in the current folder.
If Explorer.Selection.Count Then
' Get the first selected item.
Set CurrentItem = Explorer.Selection(1)
' Check for the type of the selected item as only the
' MailItem object has the Sender property.
If CurrentItem.Class = olMail Then
Set Sender = CurrentItem.Sender
' There is no sender if the item has not been sent yet.
If Sender Is Nothing Then
MsgBox "There's no sender for the current email", vbInformation
Exit Sub
End If
Set Contact = Sender.GetContact
If Not Contact Is Nothing Then
' The sender is stored in the contacts folder,
' so the contact item can be displayed.
Contact.Display
Else
' If the contact cannot be found, display the
' address entry in the properties dialog box.
Sender.Details 0
End If
End If
End If
End Sub
Bei der Zeile Set Explorer = Application.ActiveExplorer wird jedoch ein Fehler ausgelöst.
Ich vermuste, dass mir ein Verweis fehlt. Nur welcher?
Danke im Voraus und lg Alex

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

Betreff
Datum
Anwender
Anzeige
AW: Outlook
23.03.2022 17:03:58
ChrisL
Hi Alex
Ich nehme an das Makro wurde für Outlook und nicht für Excel geschrieben. Application=Excel und Excel kennt keinen ActiveExplorer.
cu
Chris
AW: Outlook
23.03.2022 17:04:21
Oberschlumpf
Hi Alex,
a) ich vermute, das gezeigte Makro ist ein OUTLOOK-Makro und wird dir direkt in EXCEL wahrsch gar nicht helfen können
b) der vielleicht fehlende Verweis könnte Microsoft Outlook x.x Object Library sein
c) und was genau willst du mit dem Makro eigtl erreichen? (hab mir das Makro nicht Zeile für Zeile durchgelesen, bin ein Fan von "menschenfreundlicher Kommunikation" :-)
Ciao
Thorsten
AW: Outlook
23.03.2022 19:41:02
Alex
Danke ChrisL und Oberschlumpf
Der Verweis auf Microsoft Outlook 16.0 Object Library iat gesetz.
Bin bei der Suche im Netz über das erste Makro getollpert und nicht erkannt das, das nur in Outlook direkt ausgeführt werden kann.
Mein Ziel ist, von Excel aus automatisch Emails zu versenden.
Der bishehr erstellte Kode:

Public Function Send(recipents As Collection, eSubject As String, eBody As String, Optional eBcc As Collection, Optional fileAttchement As OLEObject) As Boolean
'Überprüfen ist der Titel (subject) ohne Wert oder leer, dann den Benuzer
'fragen wie Weiter
If (subject = "" Or IsEmpty(subject)) Then
MsgResult = ShowMessageBox("Kein Titel! Abbrechen", vbYesNo + vbQuestion, "Emai - Versand")
If (MsgResult = vbYes) Then Send = False: Exit Function
End If
Set eItem = mailSender.CreateItem(olMailItem)
'/////////////// Set eItem.Sender = /////////' Den Sender selbst definieren mit "user@mail.de;xyz", wobei xyz das PW ist
eItem.To = GetSplitted(recipents)
If (Not eBcc Is Nothing) Then eItem.bcc = GetSplitted(eBcc)
If (subject = "" Or Not IsEmpty(subject)) Then eItem.subject = subject
eItem.HTMLBody = eBody
If (Not fileAttchement Is noting) Then eItem.Attachments.Add = fileAttchement
eItem.Send
End Function

Private Function GetSplitted(ByRef recipents As Collection) As String
Dim retVal As String
Dim i As Long
i = recipents.Count
For i = 1 To recipents.Count
If (i = 1) Then
retVal = recipents(i) & ";"
Else
retVal = retVal + recipents(i) & ";"
End If
Next
GetRecipents = Mid(retVal, 1, Len(retVal) - 1)
End Function
Wie muss da eItem.Sender implementiert werden, um das Email zu vesenden.
Email Adress und Passwort, wenn nötig noch der Servername
Lg Alex
Anzeige
AW: Outlook
23.03.2022 22:09:16
Yal
Hallo Alex,
es fehlte nicht viel:

Private Sub DisplaySenderDetails()
'unter Anbindung der Bibliothek "Micorsoft Outlook 16.0 Object Library" ("Extras", "Verweise...", ..)
Dim Explorer As Outlook.Explorer
Dim otlItem As Object
Dim Sender As Outlook.AddressEntry
Dim Contact As Outlook.ContactItem
Set Explorer = Outlook.Session.Application.ActiveExplorer
' Check whether any item is selected in the current folder.
For Each otlItem In Explorer.Selection
' Check for the type of the selected item as only the
' MailItem object has the Sender property.
If otlItem.Class = olMail Then
Set Sender = otlItem.Sender
' There is no sender if the item has not been sent yet.
If Sender Is Nothing Then
MsgBox "There's no sender for the current email", vbInformation
Exit Sub
End If
Set Contact = Sender.GetContact
If Contact Is Nothing Then
' If the contact cannot be found, display the address entry
Sender.Details 0
Else
' The sender is stored in the contacts folder, so the contact item can be displayed.
Contact.Display
End If
End If
Next
End Sub
Achte auf das Einrücken. Es macht den Code leichter zu lesen als leere Zeile.
VG
Yal
Anzeige
AW: Outlook
24.03.2022 06:42:00
Alex
Morgen zusammen
Ich stelle meine Frage nochmals zu forderst in den Thread. Leider ist die, da mir ein Fehler unterlaufen ist beim Oberschlumpf aufgetaucht!
Der Verweis auf Microsoft Outlook 16.0 Object Library iat gesetz.
Mein Ziel ist, von Excel aus automatisch Emails zu versenden.
Der bishehr erstellte Kode:

Public Function Send(recipents As Collection, eSubject As String, eBody As String, Optional eBcc As Collection, Optional fileAttchement As OLEObject) As Boolean
'Überprüfen ist der Titel (subject) ohne Wert oder leer, dann den Benuzer
'fragen wie Weiter
If (subject = "" Or IsEmpty(subject)) Then
MsgResult = ShowMessageBox("Kein Titel! Abbrechen", vbYesNo + vbQuestion, "Emai - Versand")
If (MsgResult = vbYes) Then Send = False: Exit Function
End If
Set eItem = mailSender.CreateItem(olMailItem)
  '/////////////// Set eItem.Sender = /////////' Den Sender selbst definieren mit "user@mail.de;xyz", wobei xyz das PW ist
eItem.To = GetSplitted(recipents)
If (Not eBcc Is Nothing) Then eItem.bcc = GetSplitted(eBcc)
If (subject = "" Or Not IsEmpty(subject)) Then eItem.subject = subject
eItem.HTMLBody = eBody
If (Not fileAttchement Is noting) Then eItem.Attachments.Add = fileAttchement
eItem.Send
End Function

Private Function GetSplitted(ByRef recipents As Collection) As String
Dim retVal As String
Dim i As Long
i = recipents.Count
For i = 1 To recipents.Count
If (i = 1) Then
retVal = recipents(i) & ";"
Else
retVal = retVal + recipents(i) & ";"
End If
Next
GetRecipents = Mid(retVal, 1, Len(retVal) - 1)
End Function
Wie muss da eItem.Sender implementiert werden, um das Email zu vesenden.
Email Adress und Passwort, wenn nötig noch der Servername

Lg Alex
Anzeige

Links zu Excel-Dialogen

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige