Our Blog

Extract Email address from word document

Get the code of how to Extract email addresses from a word document or html page.

 

With the script provided below, anybody can add this functionality to microsoft word.

Step 1:

If you already have a word document, proceed to step 4. Otherwise, if you intend to get these addresses from a web page, save it to your computer and open it up in word. To save it, got to File, Save As..., then choose a location on your hard drive that you can remember

Step 2:

Browse to that location where you've saved the docuemnt. It will probably have an .htm or .html extension. Both of these are fine to work with.

Step 3:

Right click on the file name and point to Open with. From the fly out menu choose Microsoft Word. The file opens up in word. Sometimes the rendition of the website may be awkward within the page. The looks do not matter.

Step 4:

Look for the Developer tab and click on it the click on the Macros button

Microsoft word developer tab

Step 5:

You are now looking at a dialogue box with a few command buttons to the right of it. In the name field type CopyAddressesToOtherDoc. Give it a description and click on create. Visual basic opens up. In the code, copy and paste the below. Save it and close visual basic.

Sub CopyAddressesToOtherDoc()

Dim Source As Document, Target As Document, myRange As Range
Set Source = ActiveDocument
Set Target = Documents.Add
Source.Activate
Selection.HomeKey Unit:=wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(findText:="[+0-9A-z._-]{1,}\@[A-z.]{1,}", _
MatchWildcards:=True, Wrap:=wdFindStop, Forward:=True) = True
Set myRange = Selection.Range
Target.Range.InsertAfter myRange & vbCr
Loop
End With
Selection.HomeKey Unit:=wdStory
Target.Activate
End Sub

This script is intellectual property of Doug Robbins - Word MVP

Step 6:

Everytime you need to extract email addresses from a document, go to Macro in the Developer tab, select the macro from the list and click on Run in the dialogue box.

We will soon open the comments.

 

- The Multiform Design Team

 

Creativity, Knowledge, Insight