#1
|
|||
|
|||
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 |
#2
|
||||
|
||||
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] |
#3
|
|||
|
|||
Quote:
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 |
#4
|
||||
|
||||
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] |
#5
|
|||
|
|||
Quote:
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 |
#6
|
||||
|
||||
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] |
#7
|
|||
|
|||
Quote:
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 |
#8
|
||||
|
||||
Try:
Find = <[0-9A-ÿ.\-]{1,}\@[0-9A-ÿ\-.]{1,}([^13 -/\:-\@\\-`\{-¿]) Replace = \1
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#9
|
|||
|
|||
Quote:
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 |
#10
|
||||
|
||||
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] |
#11
|
|||
|
|||
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 |
#12
|
||||
|
||||
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] |
#13
|
|||
|
|||
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 |
#14
|
||||
|
||||
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] |
#15
|
|||
|
|||
Hi Paul,
This solved the problem. Now its working perfectly! Thanks a lot for your help! Cheers Csaba |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
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 |