How do I mass-extract email addresses out of several word documents at once?

Anonymous
2011-07-17T15:24:20+00:00

Hello All,

I have an important question.

How do I mass-extract email addresses out of several word documents at once?

I have a folder saved on my desktop with about 12000 word documents. All these documents have an email address in them but I want to know how to export all these email addresses without opening every single file one by one.

I hope somebody can help.

Kind regards,

EM

Microsoft 365 and Office | Word | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments
Answer accepted by question author
Anonymous
2011-07-18T05:02:41+00:00

It is not possible to extract the e-mail addresses without opening the documents, but the process can be automated with a macro. The following may do what you want, so try it on a folder containing ONLY a small subset of the documents before attempting to try it on a huge number of files. The following macro will extract any e-mail address in the documents and write them, one to a line, to a new document. It will not make any permanent changes to the documents themselves.

NOTE: IT WILL CRASH IF ANY OF THE DOCUMENTS ARE PASSWORD PROTECTED

http://www.gmayor.com/installing_macro.htm

Sub BatchProcess()

Dim strFilename As String

Dim strPath As String

Dim oDoc As Document

Dim oNewDoc As Document

Dim oRng As Range

Dim hLink As Hyperlink

Dim fDialog As FileDialog

Set oNewDoc = Documents.Add

Options.AutoFormatReplaceHyperlinks = True

Set fDialog = Application.FileDialog(msoFileDialogFolderPicker)

With fDialog

    .Title = "Select folder containing the documents and click OK"

    .AllowMultiSelect = False

    .InitialView = msoFileDialogViewList

    If .Show <> -1 Then

        MsgBox "Cancelled By User", , _

               "List Folder Contents"

        Exit Sub

    End If

    strPath = fDialog.SelectedItems.Item(1)

    If Right(strPath, 1) <> "" _

       Then strPath = strPath + ""

End With

If Left(strPath, 1) = Chr(34) Then

    strPath = Mid(strPath, 2, Len(strPath) - 2)

End If

strFilename = Dir$(strPath & "*.doc?")

While Len(strFilename) <> 0

    WordBasic.DisableAutoMacros 1

    Set oDoc = Documents.Open(strPath & strFilename)

    oDoc.Range.AutoFormat

    For Each hLink In oDoc.Hyperlinks

        If InStr(1, hLink.Address, "@") Then

            oNewDoc.Range.InsertAfter hLink.Range & vbCr

        End If

    Next hLink

    oDoc.Close SaveChanges:=wdDoNotSaveChanges

    WordBasic.DisableAutoMacros 0

    strFilename = Dir$()

Wend

oNewDoc.Paragraphs.Last.Range.Delete

oNewDoc.Range.Sort

oNewDoc.Range.Find.Execute FindText:="(*^13)@", _

                           MatchWildcards:=True, _

                           ReplaceWith:="\1", _

                           Replace:=wdReplaceAll

End Sub

Was this answer helpful?

10+ people found this answer helpful.
0 comments No comments

45 additional answers

Sort by: Newest
  1. Anonymous
    2013-08-26T06:30:45+00:00

    hi Doug. This pulls out the title line for the links - thanks a ton for helping me with this. but it formats or places the titles and links kind of weird.

    For instance, this is the text and links from a sample .docx file:

    How to Remove S.M.A.R.T Check

    http://malwaretips.com/blogs/how-to-remove-s-m-a-r-t-check/

    Anvisoft: How to Remove Smart HDD Virus/S.M.A.R.T. Check? (Rogueware Removal Guide)

    http://www.dotfab.com/resources/how-to-remove-smart-hdd-viruss-m-a-r-t-check-rogueware-removal-guide/

    Anvisoft: How to Remove S.M.A.R.T. Check, S.M.A.R.T. Repair, S.M.A.R.T. HDD for Free?

    http://www.anvisoft.com/resources/how-to-remove-s-m-a-r-t-check-s-m-a-r-t-repair-s-m-a-r-t-hdd-for-free/

    Spyware Help Center: Smart Check – Virus Removal Instructions

    http://www.spywarehelpcenter.com/smart-check-virus-removal-instructions/

    Malware Experts: S.M.A.R.T Check Virus Removal Guide

    http://www.malwareexperts.com/s-m-a-r-t-check-virus-removal-guide/

    Yoo Security: SMART HDD (S.M.A.R.T. Check) Virus Removal and Fix Start Menu, Desktop Gone

    http://guides.yoosecurity.com/fake-smart-hdd-s-m-a-r-t-check-virus-removal-and-fix-start-menu-desktop-gone/

    PCInfected.com: Remove Smart Check Virus

    http://www.pcinfected.com/remove-smart-check-virus/

    BleepingComputer.com: Download RKill

    http://www.bleepingcomputer.com/download/rkill/

    Malwarebytes: Free Anti-Malware Download

    http://www.malwarebytes.org/

    CNET Download.com: AdwCleaner Download

    http://download.cnet.com/AdwCleaner/3000-7786_4-75851221.html

    BleepingComputer.com: Download Unhide

    http://www.bleepingcomputer.com/download/unhide/

    and this is what the code returns in the new document:

    Anvisoft: How to Remove S.M.A.R.T. Check, S.M.A.R.T. Repair, S.M.A.R.T. HDD for Free?

    Anvisoft: How to Remove Smart HDD Virus/S.M.A.R.T. Check? (Rogueware Removal Guide)

    BleepingComputer.com: Download RKill

    BleepingComputer.com: Download Unhide

    CNET Download.com: AdwCleaner Download

    http://download.cnet.com/AdwCleaner/3000-7786\_4-75851221.html

    http://guides.yoosecurity.com/fake-smart-hdd-s-m-a-r-t-check-virus-removal-and-fix-start-menu-desktop-gone/

    http://malwaretips.com/blogs/how-to-remove-s-m-a-r-t-check/

    http://www.anvisoft.com/resources/how-to-remove-s-m-a-r-t-check-s-m-a-r-t-repair-s-m-a-r-t-hdd-for-free/

    http://www.bleepingcomputer.com/download/rkill/

    http://www.bleepingcomputer.com/download/unhide/

    http://www.dotfab.com/resources/how-to-remove-smart-hdd-viruss-m-a-r-t-check-rogueware-removal-guide/

    http://www.malwarebytes.org/

    http://www.malwareexperts.com/s-m-a-r-t-check-virus-removal-guide/

    http://www.pcinfected.com/remove-smart-check-virus/

    http://www.spywarehelpcenter.com/smart-check-virus-removal-instructions/

    Malware Experts: S.M.A.R.T Check Virus Removal Guide

    Malware Tips: How to Remove S.M.A.R.T Check

    Malwarebytes: Free Anti-Malware Download

    PCInfected.com: Remove Smart Check Virus

    Spyware Help Center: Smart Check – Virus Removal Instructions

    Yoo Security: SMART HDD (S.M.A.R.T. Check) Virus Removal and Fix Start Menu, Desktop Gone

    for some reason it does not keep the description line and the link together. is there someway to fix that? Thank so much again for your help.

    Was this answer helpful?

    0 comments No comments
  2. Doug Robbins - MVP - Office Apps and Services 323.6K Reputation points MVP Volunteer Moderator
    2013-08-26T04:03:37+00:00

    Declare rngGet as a Range by including

    Dim rngGet As range

    and the replace the  For Each hLink construction with:

        For Each hLink In oDoc.Hyperlinks

             If InStr(1, hLink.Address, "http") Then

                Set rngGet = hLink.range

                rngGet.MoveStart wdParagraph, -1

                oNewDoc.range.InsertAfter rngGet & vbCr

             End If

         Next hLink

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2013-08-26T03:12:33+00:00

    Hi Doug.

    Here is the link to the Public doc

    http://sdrv.ms/15aP5JZ

    Was this answer helpful?

    0 comments No comments
  4. Anonymous
    2013-08-26T03:02:54+00:00

    Hi Doug.

    Thanks for the quick reply. I got Graham's code to work for pulling out the JUST the hyperlinks.. was actually quite easy just replaced the "@" with "http" and voila. But still no idea how to pull out the description line just before the link. I will post it to local sky drive and post link here forthwith.

    thanks again.

    Was this answer helpful?

    0 comments No comments