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

Fehler bei Makro auslesen von Text aus Outloock

Fehler bei Makro auslesen von Text aus Outloock
24.02.2015 08:40:27
Text
Hallo zusammen,
ich habe folgendes Makro aus dem Internet für mich angepasst.
Es soll Standarttexte aus Mails in auslesen und in Excel eintragen.
Funktioniert auch soweit, nur ich habe in der Exceltabelle eine Verschiebung
und finde den Fehler nicht.
Makro:
Option Explicit
Sub TestOutlookMails()
Dim olApp      As Object   ' das Outlook-Objekt
Dim objFolder  As Object   ' der Standard-Posteingangsordner
Dim objItem    As Object   ' ein Objekt in objFolder
Dim i          As Long     ' Zeilennummer
Dim objRe      As Object   ' ein Regular-Expression Objekt
Dim objMc      As Object   ' eine MatchCollection, das Ergebnis von objRe.Execute
Dim objMatch   As Object   ' ein Match, d.h. ein Eintrag der Form "irgendwas:sonstwas"
Dim objDic     As Object   ' ein Dictionary-Objekt, Key sind die möglichen Werte vor dem  _
Doppelpunkt, Item ist die Spaltenummer wo das hinsoll
Dim varKey     As Variant  ' ein Key im Dictionary
Dim strKey     As String   ' dito
Set objDic = CreateObject("scripting.dictionary")
i = 1
Cells(1, 1).Value = "Betreff"
For Each varKey In Array("Auftragsnummer", "Kundenname", "Kundenanschrift", "Mitarbeiter", "  _
_
Bewertung", "Datum")
i = i + 1
objDic(varKey) = i
Cells(1, i).Value = varKey
Next
Set objRe = CreateObject("vbscript.regexp")
objRe.Global = True
objRe.MultiLine = True
objRe.Pattern = "^(.*?):[ \t]*(.*?)[\r\n]?$"
Set olApp = CreateObject("outlook.application")
'Set objFolder = olApp.GetNameSpace("MAPI").GetDefaultFolder(6) ' 6 = olFolderInbox   '  _
Posteingang
Set objFolder = olApp.GetNamespace("MAPI").GetDefaultFolder(6).Folders("Kappelhoff"). _
Folders("Extra")  'mit Unterordner
i = 2
For Each objItem In objFolder.Items
If TypeName(objItem) = "MailItem" Then
Set objMc = objRe.Execute(objItem.Body)
If objMc.Count > 0 Then
Cells(i, 1).Value = objItem.Subject
i = i + 1
For Each objMatch In objMc
strKey = objMatch.Submatches(0)
If objDic.Exists(strKey) Then Cells(i, objDic(strKey)) = objMatch.Submatches(1)
Next
End If
End If
Next
objDic.RemoveAll
Set objDic = Nothing
Set objMc = Nothing
Set objRe = Nothing
Set objFolder = Nothing
Set olApp = Nothing
End Sub

-----------------------------------------------------------
Die Exceldatei ist hier zufinden :
https://www.herber.de/bbs/user/95941.xlsm
Danke schon mal.
Werner

2
Beiträge zum Forumthread
Beiträge zu diesem Forumthread

Betreff
Datum
Anwender
Anzeige
AW: Fehler bei Makro auslesen von Text aus Outloock
24.02.2015 08:58:25
Text
Hallo Werner,
Und jetzt? Sollen wir alles selbst testen? Ich hab kein Outlook mit deinen Daten!
Ich vermute mal, dass untenstehender Code-Teil am falschen Ort den i(ndex) erhöht und eigentlich so lauten sollte?
         If objMc.Count > 0 Then
Cells(i, 1).Value = objItem.Subject
For Each objMatch In objMc
strKey = objMatch.Submatches(0)
If objDic.Exists(strKey) Then Cells(i, objDic(strKey)) = objMatch.Submatches(1)
Next
i = i + 1
End If

Gruess Hansueli

AW: Fehler bei Makro auslesen von Text aus Outloock
24.02.2015 09:17:38
Text
Hallo Hansueli,
dein Tipp war super, jetzt funktionierts auch ohne das du die Daten hattest.
Danke nochmal.
Viele Grüße Werner
Anzeige

315 Forumthreads zu ähnlichen Themen

Anzeige
Anzeige
Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige