![]() |
If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Search this Thread | Display Modes |
#1
|
|||
|
|||
![]()
Hello,
I have an Outlook folder full of undeliverable emails. I am trying to develop a macro that will go to the folder, open each email, extract the reported failed address frm the body of the email, and save the address to a file. The failed address regularly appears in angle brackets in the body of the message. I can't seem to identify the best approach to this. Can you tell me what I'm doing wrong, or if there is a more straitforward approach. I tried an advanced search, but it stalls on the command line. I need to get this to work so I can install the loop, and add a file location in which to save the addresses located in the body of the messages. Currently it's a form with one button: Private Sub CommandButton1_Click() Dim objSch As Search Dim strF As String Dim strS As String Dim strTag As String strS = "undeliverables" strF = "urn:schemas:httpmail:body LIKE '' & * & ''" strTag = "EmailSearch" ' TODO: Replace Application with the declared and set ' Outlook Application object objSch = Application.AdvancedSearch(strS, strF, False, strTag) End Sub -- Phantom Researcher |
Ads |
#2
|
|||
|
|||
![]()
Actually, I am trying this code:
Private Sub FindSaveAddressInEmails() On Error Resume Next Dim objNS As Outlook.NameSpace Dim objFolder As Outlook.MAPIFolder Dim objItem As Object Dim strFind As String Dim objItems As Outlook.Items Dim objSch As Search Dim strF As String Dim strS As String Dim strTag As String Set objNS = Application.GetNamespace("MAPI") Set objFolder = objNS.PickFolder If objFolder Is Nothing Then Exit Sub Set objItems = objFolder.Items For Each objItem In objItems strS = "undeliverables" strF = "urn:schemas:httpmail:body LIKE '' & * & ''" strTag = "EmailSearch" objSch = Application.AdvancedSearch(strS, strF, False, strTag) ' objItem.Save Next MsgBox "Finished.", vbOKOnly + vbInformation Set objNS = Nothing Set objFolder = Nothing Set objItem = Nothing Set objItems = Nothing End Sub -- Phantom Researcher "Edward" wrote: Hello, I have an Outlook folder full of undeliverable emails. I am trying to develop a macro that will go to the folder, open each email, extract the reported failed address frm the body of the email, and save the address to a file. The failed address regularly appears in angle brackets in the body of the message. I can't seem to identify the best approach to this. Can you tell me what I'm doing wrong, or if there is a more straitforward approach. I tried an advanced search, but it stalls on the command line. I need to get this to work so I can install the loop, and add a file location in which to save the addresses located in the body of the messages. Currently it's a form with one button: Private Sub CommandButton1_Click() Dim objSch As Search Dim strF As String Dim strS As String Dim strTag As String strS = "undeliverables" strF = "urn:schemas:httpmail:body LIKE '' & * & ''" strTag = "EmailSearch" ' TODO: Replace Application with the declared and set ' Outlook Application object objSch = Application.AdvancedSearch(strS, strF, False, strTag) End Sub -- Phantom Researcher |
#3
|
|||
|
|||
![]()
Am Sat, 25 Feb 2006 11:37:19 -0800 schrieb Edward:
Edward, please see the VBA help for a sample of AdvancedSearch. strF = "urn:schemas:httpmail:body LIKE '' & * & ''" For searching something that is enclosed in the brackets use: strF = "urn:schemas:httpmail:textdescription LIKE '%'" -- Viele Gruesse / Best regards Michael Bauer - MVP Outlook -- www.vbOffice.net -- Actually, I am trying this code: Private Sub FindSaveAddressInEmails() On Error Resume Next Dim objNS As Outlook.NameSpace Dim objFolder As Outlook.MAPIFolder Dim objItem As Object Dim strFind As String Dim objItems As Outlook.Items Dim objSch As Search Dim strF As String Dim strS As String Dim strTag As String Set objNS = Application.GetNamespace("MAPI") Set objFolder = objNS.PickFolder If objFolder Is Nothing Then Exit Sub Set objItems = objFolder.Items For Each objItem In objItems strS = "undeliverables" strF = "urn:schemas:httpmail:body LIKE '' & * & ''" strTag = "EmailSearch" objSch = Application.AdvancedSearch(strS, strF, False, strTag) ' objItem.Save Next MsgBox "Finished.", vbOKOnly + vbInformation Set objNS = Nothing Set objFolder = Nothing Set objItem = Nothing Set objItems = Nothing End Sub |
#4
|
|||
|
|||
![]()
The VBA help isn't too clear on how to access the results of the
AdvancedSearch. Do I need a streamwriter to get the info to a text file, or can I access the object directly somehow? Much thanks. -- Phantom Researcher "Michael Bauer" wrote: Am Sat, 25 Feb 2006 11:37:19 -0800 schrieb Edward: Edward, please see the VBA help for a sample of AdvancedSearch. strF = "urn:schemas:httpmail:body LIKE '' & * & ''" For searching something that is enclosed in the brackets use: strF = "urn:schemas:httpmail:textdescription LIKE '%'" -- Viele Gruesse / Best regards Michael Bauer - MVP Outlook -- www.vbOffice.net -- Actually, I am trying this code: Private Sub FindSaveAddressInEmails() On Error Resume Next Dim objNS As Outlook.NameSpace Dim objFolder As Outlook.MAPIFolder Dim objItem As Object Dim strFind As String Dim objItems As Outlook.Items Dim objSch As Search Dim strF As String Dim strS As String Dim strTag As String Set objNS = Application.GetNamespace("MAPI") Set objFolder = objNS.PickFolder If objFolder Is Nothing Then Exit Sub Set objItems = objFolder.Items For Each objItem In objItems strS = "undeliverables" strF = "urn:schemas:httpmail:body LIKE '' & * & ''" strTag = "EmailSearch" objSch = Application.AdvancedSearch(strS, strF, False, strTag) ' objItem.Save Next MsgBox "Finished.", vbOKOnly + vbInformation Set objNS = Nothing Set objFolder = Nothing Set objItem = Nothing Set objItems = Nothing End Sub |
#5
|
|||
|
|||
![]()
Am Sun, 26 Feb 2006 17:29:02 -0800 schrieb Edward:
Accessing the result is the one thing and very clear: Use the AdvancedSearchComplete event. If that fires then the search is complete and it provides you with a Search object which has a Result property to access all the result items. What you want to do with that result is another thing and can't be part of the help file. You can use e.g. the FileSystemObject of the Scripting Runtime Library to write any data in a text file. -- Viele Gruesse / Best regards Michael Bauer - MVP Outlook -- www.vbOffice.net -- The VBA help isn't too clear on how to access the results of the AdvancedSearch. Do I need a streamwriter to get the info to a text file, or can I access the object directly somehow? Much thanks. |
#6
|
|||
|
|||
![]()
Still confused. Any idea why this doesn't work:
Sub SearchUndeliverablesFolder() 'Searches the Inbox Dim objSch As Search Const strF As String = "urn:schemas:httpmail:textdescription LIKE '%'" Const strS As String = "undeliverables" Const strTag As String = "GITem" Set objSch = Application.AdvancedSearch(Scope:=strS, _ Filter:=strF, Tag:=strTag) End Sub Public Sub Application_AdvancedSearchComplete(ByVal objSch As Search) Dim objRsts As Results Set fs = CreateObject("Scripting.FileSystemObject") Set a = fs.CreateTextFile("c:\UndelResults.txt", True) MsgBox "The search " & objSch.Tag & "has completed." Set objRsts = objSch.Results 'Display number in Results collection MsgBox "There are " & objRsts.Count & "address items" 'Write each member of Results to file For Each Item In objRsts a.WriteLine (Item) 'took this out: objRsts.WriteLine Item Next a.Close MsgBox "end of write subroutine", vbOKOnly + vbInformation End Sub MsgBox "Finished.", vbOKOnly + vbInformation Set objNS = Nothing Set objFolder = Nothing Set objItem = Nothing Set objItems = Nothing End Sub tHANKS -- Phantom Researcher "Michael Bauer" wrote: Am Sun, 26 Feb 2006 17:29:02 -0800 schrieb Edward: Accessing the result is the one thing and very clear: Use the AdvancedSearchComplete event. If that fires then the search is complete and it provides you with a Search object which has a Result property to access all the result items. What you want to do with that result is another thing and can't be part of the help file. You can use e.g. the FileSystemObject of the Scripting Runtime Library to write any data in a text file. -- Viele Gruesse / Best regards Michael Bauer - MVP Outlook -- www.vbOffice.net -- The VBA help isn't too clear on how to access the results of the AdvancedSearch. Do I need a streamwriter to get the info to a text file, or can I access the object directly somehow? Much thanks. |
#7
|
|||
|
|||
![]()
Am Wed, 15 Mar 2006 18:17:27 -0800 schrieb Edward:
As I don´t know what doesn´t work, please read this: http://groups.google.de/group/micros...865987f49346ca It descripes how to use non default folders in the scope. -- Viele Gruesse / Best regards Michael Bauer - MVP Outlook -- www.vbOffice.net -- Still confused. Any idea why this doesn't work: Sub SearchUndeliverablesFolder() 'Searches the Inbox Dim objSch As Search Const strF As String = "urn:schemas:httpmail:textdescription LIKE '%'" Const strS As String = "undeliverables" Const strTag As String = "GITem" Set objSch = Application.AdvancedSearch(Scope:=strS, _ Filter:=strF, Tag:=strTag) End Sub Public Sub Application_AdvancedSearchComplete(ByVal objSch As Search) Dim objRsts As Results Set fs = CreateObject("Scripting.FileSystemObject") Set a = fs.CreateTextFile("c:\UndelResults.txt", True) MsgBox "The search " & objSch.Tag & "has completed." Set objRsts = objSch.Results 'Display number in Results collection MsgBox "There are " & objRsts.Count & "address items" 'Write each member of Results to file For Each Item In objRsts a.WriteLine (Item) 'took this out: objRsts.WriteLine Item Next a.Close MsgBox "end of write subroutine", vbOKOnly + vbInformation End Sub MsgBox "Finished.", vbOKOnly + vbInformation Set objNS = Nothing Set objFolder = Nothing Set objItem = Nothing Set objItems = Nothing End Sub tHANKS |
#8
|
|||
|
|||
![]()
Hi Edward,
Did you ever get the code to work for collecting all undeliverables then writing just the email addresses to a seperate file? If so have I could really use it as I have a large number of undeliverables that need listing. Cheers Dave |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
How do I append text to the body of a email? | Beginner | Outlook and VBA | 2 | February 9th 06 09:36 PM |
Missing Body Text But Appears When Replying or Forwarding | Asin | Outlook - Installation | 0 | February 7th 06 01:42 AM |
Script to search Outlook message body | aptrsn1 | Outlook and VBA | 1 | January 27th 06 03:42 PM |
Photos embedded in body of text? | Pete Stolz | Outlook - General Queries | 0 | January 22nd 06 03:58 PM |
How do I get incoming .jpg's to show up in my text body | Scott | Outlook - General Queries | 1 | January 11th 06 08:47 PM |