Outlook 2007 Search Through E-Mail

Status
Not open for further replies.
There was no error message...it just turned yellow.....I will try what you said right now
 
There was no error message...it just turned yellow.....I will try what you said right now
 
There was no error message...it just turned yellow.....I just tried it and same yellow and did not do it....not if after the words Folders I put in the name of the folder as a ("Name").Items....that goes to the specific folder...but I want it to simply search all folders
 
So it sounds like its not pointing at the right folder. I'll have to sleep on it.
 
Just in case this will show you what to tell me.....this is a code that someone gave me, that when I run it from the top macro, it displays all contacts from every where I think....so is there something to put in this so it only displays the contact of the email address from the note field of the received email....or is there anything from this code, to add to your code so it does it for all folders?

Sub GetValueUsingRegEx39()
Dim obj As Object
Dim Selection As Selection
Dim olMail As Object 'Outlook.MailItem
Dim Reg1 As Object
Dim M1 As Object
Dim M As Object
Dim strAddress As String
Dim myContacts As Items
Dim myItem As contactItem
Set Selection = Application.ActiveExplorer.Selection
Set objNS = Application.GetNamespace("MAPI")
processFolder (objNS.GetDefaultFolder(olFolderContacts))
End Sub
Private Sub processFolder(ByVal oParent As outlook.MAPIFolder)
Dim oFolder As outlook.MAPIFolder
Dim oContact As outlook.contactItem
For Each oContact In oParent.Items
oContact.Display
Next
If (oParent.Folders.Count > 0) Then
For Each oFolder In oParent.Folders
Call processFolder(oFolder)
Next
End If
End Sub
 
The processFolder sub should work if you can work it in - it checks all of the folders.

Try this one -

Code:
Sub GetValueUsingRegEx3() 
Dim obj As Object 
Dim Selection As Selection 
Dim olMail As Object 'Outlook.MailItem 
Dim Reg1 As Object 
Dim M1 As Object 
Dim M As Object 
Dim strAddress As String 
Dim myContacts As Items 
 
Set Selection = Application.ActiveExplorer.Selection 
 
For Each obj In Selection 
Set olMail = obj 
Set Reg1 = CreateObject("VBScript.RegExp") 
With Reg1 
.Pattern = "(([\w-\.]*\@[\w-\.]*)\s*)" 
.IgnoreCase = True 
.Global = False 
End With 
 
If Reg1.TEst(olMail.Body) Then 
 
Set M1 = Reg1.Execute(olMail.Body) 
For Each M In M1 
strAddress = M.SubMatches(1) 
Debug.Print strAddress 
processFolder (objNS.GetDefaultFolder(olFolderContacts)) 
 
Next 
 
End If 
Next 
End Sub 
 
Private Sub processFolder(ByVal oParent As outlook.MAPIFolder) 
 
Dim oFolder As outlook.MAPIFolder 
Dim oContact As outlook.contactItem 
Dim myItem As contactItem 
 
For Each oContact In oParent.Items 
Set myItem = oContacts.Find("[Email1Address]=" & strAddress) 
   myItem.Display 
Next 
If (oParent.Folders.Count > 0) Then 
For Each oFolder In oParent.Folders 
Call processFolder(oFolder) 
Next 
End If 
End Sub
 
Thanks much. When I ran it, it did not do it and the following line turns yellow with know specific error:

processFolder (objNS.GetDefaultFolder(olFolderContacts))

And also, when I move my mouse to that line, is shows that str.addresss = the email address in the note field of the email I received.
 
it's mothers day and i took the weekend off. :) i looked at it yesterday and it's definitely something with the processfolder line, but i don't know what is wrong, sorry.
 
If you can figure it out that would be great. Happy Mothers Day!
 
Update please....I really need to do this!!!
 
Update please....I really need to do this!!!
 
try this - i have no idea if it works on subfolders as i don't use subfolders, but it definitely finds the match in the contacts folder.

Code:
Dim strAddress As String 
Sub GetValueUsingRegEx3() 
Dim obj As Object 
Dim Selection As Selection 
Dim olMail As Object 'Outlook.MailItem 
Dim Reg1 As Object 
Dim M1 As Object 
Dim M As Object 
 
Set objNS = Application.GetNamespace("MAPI") 
Set Selection = Application.ActiveExplorer.Selection 
 
For Each obj In Selection 
Set olMail = obj 
Set Reg1 = CreateObject("VBScript.RegExp") 
With Reg1 
.Pattern = "(([\w-\.]*@[\w-\.]*)\s*)" 
.IgnoreCase = True 
.Global = False 
End With 
 
If Reg1.test(olMail.Body) Then 
 
Set M1 = Reg1.Execute(olMail.Body) 
For Each M In M1 
strAddress = M.SubMatches(1) 
Debug.Print strAddress & " " & Time 
processFolder (objNS.GetDefaultFolder(olFolderContacts)) 
 
Next 
 
End If 
Next 
End Sub 
 
Private Sub processFolder(ByVal oParent As Outlook.MAPIFolder) 
Dim oFolder As Outlook.MAPIFolder 
Dim oContact As Outlook.ContactItem 
On Error Resume Next 
For Each oContact In oParent.Items 
  If oContact.Email1Address = strAddress Then 
    oContact.Display 
  End If 
Next 
If (oParent.Folders.Count > 0) Then 
For Each oFolder In oParent.Folders 
Call processFolder(oFolder) 
Next 
End If 
End Sub
 
I moved Dim strAddress As String below the Sub title.....and when I ran it, it simply opens up all contacts
 
You need it outside the macro because you are passing the straddress value to the processfolder sub -
For Each oContact In oParent.Items
If oContact.Email1Address = strAddress Then
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
J outlook 2007 doesn't let me choose which .pst to search Using Outlook 2
S outlook 2007 calendar search Using Outlook 6
S Outlook 2007 Calendar instant search problem. Windows 7 Using Outlook 4
S Outlook 2007 Calendar instant search problem. Windows 7 Using Outlook 0
L Outlook 2007 - Macro Re Search Using Outlook 16
L Outlook 2007 Criteria Search Using Outlook 9
L Outlook 2007 Search All Fields in Contacts Using Outlook 1
L Outlook 2007 Macro Search Contacts Using Outlook 9
L Outlook 2007 Search Folder Using Outlook 1
Z outlook 2007 - opening a contact from the search results doesn't use the custom form Using Outlook 10
M Search emails not working in Outlook 2007 Using Outlook 1
G Outlook 2007 compound (OR) instant search break down Using Outlook 14
A Outlook 2007 message search results loses focus Using Outlook 7
L Outlook 2007 E-Mail Search Using Outlook 9
L Outlook 2007 E-mail Search Using Outlook 19
P Disable Instant Search in Outlook 2007 Outlook VBA and Custom Forms 9
T Outlook 2007 Indexing Options and Advanced Search options disabled Using Outlook 5
D Outlook 2007 Recovering E-Mails Using Outlook 0
W Transfer Outlook 2016 autocomplete file to Outlook 2007 Using Outlook 1
C Outlook 2007 Removing then adding account restores junk email processing Using Outlook 0
S Outlook 2007 crash linked to gdiplus.dll Using Outlook 0
S Outlook 2007 - Automatic purge fail Using Outlook 0
D Outlook 2007 vs. Outlook 2010 -- ToDo Bar Using Outlook 0
D Outlook 2007 on 365 Using Outlook.com accounts in Outlook 2
S Macro for other actions - Outlook 2007 Outlook VBA and Custom Forms 23
S Verwendung von Outlook 2007 Using Outlook 0
A Arthur needs help with 2007 Outlook e-mail Using Outlook.com accounts in Outlook 3
M PST import from Outlook 2007 to 2010 - Address Book contacts all in 1 group Using Outlook 4
B Migrate Outlook 2007 to Office 365 Using Outlook 3
X I have met my waterloo trying to resolve embedded graphics problem with outlook 2007 and now 2016 Using Outlook 1
R Outlook 2007 only loads some appointments Using Outlook 0
C Move Outlook 2007 to new PC with Outlook 365 Using Outlook 3
J Outlook 2007 Hide Messages Option not Available Using Outlook 2
B Server errors Outlook 2007 Using Outlook 1
S Reboot of frozen windows7 results in changed outlook 2007 settings Using Outlook 1
S Outlook 2007 printing wrong email address at top of page Using Outlook 8
M Configure outlook 2007 to accept digital signatures Using Outlook 2
D Outlook 2007 crashes when opening an email Using Outlook 2
R New chap saying hello and needing advice on Outlook 2007 thumbnails Using Outlook 3
icacream From Outlook 2007 to 2016 ! Using Outlook 9
vodkasoda Object could not be found Error in Outlook 2007 Outlook VBA and Custom Forms 5
S Outlook 2007: Address Cards allow entering text! Why? Using Outlook 3
S View Appointment in Text Wrap in Outlook 2007 Month Calendar View Using Outlook 0
L Outlook 2007 Separate the Send/Receive functions Using Outlook 2
M Outlook 2007 Contacts Glitch: Creating a new email Using Outlook 1
C Move from Outlook 2007 Enterprise (MOE) to Outlook Pro plus 2007 Using Outlook 1
J reinstalling Outlook 2007 asking for user name & password Using Outlook 14
P outlook addin unloaded in office 2007 Using Outlook 0
B Fonts in Outlook 2007 Using Outlook 4
R Add Exchange Account to existing POP3 Outlook 2007 Profile Using Outlook 0

Similar threads

Back
Top