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: Most helpful
  1. Doug Robbins - MVP - Office Apps and Services 323.6K Reputation points MVP Volunteer Moderator
    2013-08-26T07:14:29+00:00

    Delete the following lines of code:

    oNewDoc.Paragraphs.Last.Range.Delete

    oNewDoc.Range.Sort

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

    MatchWildcards:=True, _

    ReplaceWith:="\1", _

    Replace:=wdReplaceAll

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2013-08-26T06:59:12+00:00

    yep, works perfect with a single document. Thanks. I tried to integrate with  Graham's code, though, so i could strip links out of docs in a folder. This is what i came up with, please tell me if it looks okay:

    Private Sub ExtractLinks_Click()

    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 rngGet As Range

    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, "http") Then

                Set rngGet = hLink.Range

                rngGet.MoveStart wdParagraph, -1

                oNewDoc.Range.InsertAfter rngGet & 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

    Thanks a bunch!

    Was this answer helpful?

    0 comments No comments
  3. Doug Robbins - MVP - Office Apps and Services 323.6K Reputation points MVP Volunteer Moderator
    2013-08-26T06:47:33+00:00

    Using the following macro that contains that code on the document that you posted at http://sdrv.ms/15aP5JZ

    Dim oDoc As Document, oNewDoc As Document

    Dim rngGet As range

    Set oDoc = ActiveDocument

    Set oNewDoc = Documents.Add

    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

    created a document containing the following

    TheGurdian: Replacing a Windows Laptop's Hard Drive

    http://www.guardian.co.uk/technology/askjack/2012/feb/02/ask-jack-windows-laptop-hard-drive

    Windows Eight Forums: How to Create a "System Repair Disc" (CD/DVD) in Windows 8

    http://www.eightforums.com/tutorials/2855-system-repair-disc-create-windows-8-a.html

    ARS Technica: Using Windows 8′S "Hidden" Backup to Clone and Recover Your Whole PC

    http://arstechnica.com/information-technology/2012/12/using-windows-8s-hidden-backup-to-clone-and-recover-your-whole-pc/

    TechRepublic: Restore Windows 8 with System Image Recovery

    http://www.techrepublic.com/blog/window-on-windows/restore-windows-8-with-system-image-recovery/7464

    Microsoft Support: How to Create a System Image to Refresh Your Windows 8 PC

    http://support.microsoft.com/kb/2748351

    Windows Eight Forums: How to Do a System Image Recovery in Windows 8

    http://www.eightforums.com/tutorials/9064-system-image-recovery-restore-image-computer-windows-8-a.html

    BleepingComputer.com: How to Use System Image Recovery in the Windows 7 and Windows 8 Recovery Environment

    http://www.bleepingcomputer.com/tutorials/system-image-recovery-in-windows-7-8/

    and with the sample text that you posted in your response, it creates a document containing

    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/

    Was this answer helpful?

    0 comments No comments
  4. 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