Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 05-30-2013, 07:34 AM
Chayes Chayes is offline Find all email addresses in word document and delete Windows XP Find all email addresses in word document and delete Office 2003
Advanced Beginner
Find all email addresses in word document and delete
 
Join Date: May 2012
Posts: 79
Chayes is on a distinguished road
Default Find all email addresses in word document and delete

Hi

I'm trying to construct a Find and Replace phrase to find all the email addresses in a Word document and then delete them. I'm struggling I think because the @ symbol is reserved by Word.

Can someone help? Grateful for any advice.





Best Wishes
Reply With Quote
  #2  
Old 05-30-2013, 02:11 PM
macropod's Avatar
macropod macropod is offline Find all email addresses in word document and delete Windows 7 32bit Find all email addresses in word document and delete Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Hi Chayes,

Are the email addresses formatted as hyperlinks (i.e. blue/underlined and pressing Shift-F9 after selecting one displays a hyperlink field)?
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 05-30-2013, 02:27 PM
Chayes Chayes is offline Find all email addresses in word document and delete Windows XP Find all email addresses in word document and delete Office 2003
Advanced Beginner
Find all email addresses in word document and delete
 
Join Date: May 2012
Posts: 79
Chayes is on a distinguished road
Default

Quote:
Originally Posted by macropod View Post
Hi Chayes,

Are the email addresses formatted as hyperlinks (i.e. blue/underlined and pressing Shift-F9 after selecting one displays a hyperlink field)?

HI

They are unformatted plain text. I'm trying to select them either by Search and replace or by VBA and then remove them , but am having trouble getting the code right.

Thanks for your help.

Best Wishes
Reply With Quote
  #4  
Old 05-30-2013, 03:03 PM
macropod's Avatar
macropod macropod is offline Find all email addresses in word document and delete Windows 7 32bit Find all email addresses in word document and delete Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

You should be able to use a wildcard Find/Replace, where:
Find = <[0-9A-Za-z.]{1,}\@[!. ]{1,}.*>
Replace = nothing
No code required. Of course, if you're doing this regularly, simply record the above as a macro.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 05-30-2013, 03:21 PM
Chayes Chayes is offline Find all email addresses in word document and delete Windows XP Find all email addresses in word document and delete Office 2003
Advanced Beginner
Find all email addresses in word document and delete
 
Join Date: May 2012
Posts: 79
Chayes is on a distinguished road
Default

Quote:
Originally Posted by macropod View Post
You should be able to use a wildcard Find/Replace, where:
Find = <[0-9A-Za-z.]{1,}\@[!. ]{1,}.*>
Replace = nothing
No code required. Of course, if you're doing this regularly, simply record the above as a macro.
Hi Paul

Ok thanks for that. it works like a dream and clears all the email addresses out. Brilliant.

Just A FYI - It did miss one email address which has an underscore in it , but I was able to remove it manually. It only removed the text after the underscore.



Best Wishes


Colin
Reply With Quote
  #6  
Old 05-30-2013, 03:25 PM
macropod's Avatar
macropod macropod is offline Find all email addresses in word document and delete Windows 7 32bit Find all email addresses in word document and delete Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

OK, to handle those, it's just a matter of adding the underscore to the Find expression:
Find = <[0-9A-Za-z._]{1,}\@[!. ]{1,}.*>
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #7  
Old 05-30-2013, 04:15 PM
Chayes Chayes is offline Find all email addresses in word document and delete Windows XP Find all email addresses in word document and delete Office 2003
Advanced Beginner
Find all email addresses in word document and delete
 
Join Date: May 2012
Posts: 79
Chayes is on a distinguished road
Default

Quote:
Originally Posted by macropod View Post
OK, to handle those, it's just a matter of adding the underscore to the Find expression:
Find = <[0-9A-Za-z._]{1,}\@[!. ]{1,}.*>

Hi

Ok Thanks for this.

I ran it and it does deal with those with underscores perfectly.

I've attached a file with 20 sample email addresses of varying configuration so you can see the effect of the formula. Results are pretty good.



Best Wishes
Attached Files
File Type: doc Email-remove practice.doc (20.0 KB, 17 views)
Reply With Quote
  #8  
Old 05-30-2013, 05:47 PM
macropod's Avatar
macropod macropod is offline Find all email addresses in word document and delete Windows 7 32bit Find all email addresses in word document and delete Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Try:
Find = <[0-9A-ÿ.\-]{1,}\@[0-9A-ÿ\-.]{1,}([^13 -/\:-\@\\-`\{-¿])
Replace = \1
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #9  
Old 05-30-2013, 06:43 PM
Chayes Chayes is offline Find all email addresses in word document and delete Windows XP Find all email addresses in word document and delete Office 2003
Advanced Beginner
Find all email addresses in word document and delete
 
Join Date: May 2012
Posts: 79
Chayes is on a distinguished road
Smile

Quote:
Originally Posted by macropod View Post
Try:
Find = <[0-9A-ÿ.\-]{1,}\@[0-9A-ÿ\-.]{1,}([^13 -/\:-\@\\-`\{-¿])
Replace = \1
Hi Paul

I have to say I am seriously impressed. This cleaned them all out with no residual charcters of any kind. Fantastic.

RegEx was always an interest but never a strong point of mine , but I'm going to try to work through the logic of the formula for my own interest. Thanks again.


Best Wishes
Reply With Quote
  #10  
Old 05-30-2013, 06:51 PM
macropod's Avatar
macropod macropod is offline Find all email addresses in word document and delete Windows 7 32bit Find all email addresses in word document and delete Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

To give you a hand:
< refers to the start of a word
[0-9A-ÿ.\-]{1,} (used twice) refers to a string of any length containing the specified range of characters
@ is an obvious requirement for an email address
([^13 -/\:-\@\\-`\{-¿]) says to tag whatever the first character is after the email address, which could be any punctuation character, a space, paragraph break, etc. (I got lazy and didn't bother excluding some non-punctuation characters)
\1 tells the replacement to use the first tagged Find expression.

I'll leave it to you to figure out the rest
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #11  
Old 10-10-2013, 04:05 AM
Deemer84 Deemer84 is offline Find all email addresses in word document and delete Windows XP Find all email addresses in word document and delete Office 2007
Novice
 
Join Date: Oct 2013
Posts: 3
Deemer84 is on a distinguished road
Default

Hi,

Hope you still check this forum. I'm quite new to VBA and I'm struggling with a program like this. Can you write an example pls how to use the above code in a sub? When I try to insert it, it says syntax error for me. Thx
Reply With Quote
  #12  
Old 10-10-2013, 02:25 PM
macropod's Avatar
macropod macropod is offline Find all email addresses in word document and delete Windows 7 32bit Find all email addresses in word document and delete Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

The first thing to establish is that the wildcard Find/Replace works for you - different regional settings can necessitate some changes. Once it is established that the Find/Replace does work, creating a macro for it is a simple matter of switching on the macro recorder and recording the process.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #13  
Old 10-21-2013, 07:16 AM
Deemer84 Deemer84 is offline Find all email addresses in word document and delete Windows XP Find all email addresses in word document and delete Office 2007
Novice
 
Join Date: Oct 2013
Posts: 3
Deemer84 is on a distinguished road
Default

Hi Paul,

Thanks for your reply! I read some article about wildcards and now I'm more familiar with it, however I'm still having some trouble with solving this problem.

I tried with your code and I also tried my version: FIND = [A-Za-z0-9\-,_]{2,}[\@]{1}[A-Za-z0-9\-._]{2,}

Both are giving me the same error message when I try to search: "The Find What text contains a Pattern Match expression which is not valid"

Can you help me how to solve it?

Thank you
Reply With Quote
  #14  
Old 10-21-2013, 08:03 PM
macropod's Avatar
macropod macropod is offline Find all email addresses in word document and delete Windows 7 32bit Find all email addresses in word document and delete Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

That suggests you're using a system that requires semi-colon separators. For that, change both instances of {2,} to {2;}.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #15  
Old 10-22-2013, 06:30 AM
Deemer84 Deemer84 is offline Find all email addresses in word document and delete Windows XP Find all email addresses in word document and delete Office 2007
Novice
 
Join Date: Oct 2013
Posts: 3
Deemer84 is on a distinguished road
Default

Hi Paul,

This solved the problem. Now its working perfectly! Thanks a lot for your help!

Cheers
Csaba
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Find all email addresses in word document and delete simpler way to delete a particular page in a Word document??? tinfanide Word VBA 9 02-15-2019 02:12 PM
Selective Find and Replace in addresses Chayes Word 2 06-16-2012 04:21 PM
Can't delete word document Sparky Word 1 04-18-2012 12:20 AM
delete email message via blackberry and have it delete on my pop3 and my outlook Iamthestorm Outlook 2 10-28-2010 12:21 AM
How Many Email Addresses Can You email at one time in Outlook zinfandel72 Outlook 2 08-04-2008 06:39 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 04:11 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft