Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 06-30-2014, 07:29 PM
macropod's Avatar
macropod macropod is offline copy a specific words to excel list Windows 7 32bit copy a specific words to excel list Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,521
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

Since you want to get a whole folder full of data, all on different worksheets, this would be better with an Excel macro instead of a Word macro. Simply add the following macro to an Excel workbook, then run it. Note that the code requires a reference to the Word object model. To do this in the VBE, choose Tools|References then scroll down to the Microsoft Word entry and check it.


Code:
Sub GetWordLists()
     'Note: this code requires a reference to the Word object model
    Application.ScreenUpdating = False
    Dim wdApp As New Word.Application
    Dim wdDoc As Word.Document
    Dim strFolder As String, strFile As String
    Dim WkBk As Workbook, WkSht As Worksheet, i As Long
    strFolder = GetFolder
    If strFolder = "" Then Exit Sub
    Set WkBk = ThisWorkbook
    strFile = Dir(strFolder & "\*.docx", vbNormal)
    While strFile <> ""
        Set WkSht = WkBk.Sheets.Add
        i = 1
        WkSht.Cells(i, 1) = strFolder & "\" & strFile
        WkSht.Cells(i, 2) = "Page"
        WkSht.Name = Split(strFile, ".doc")(0)
        Set wdDoc = wdApp.Documents.Open(Filename:=strFolder & "\" & strFile, AddToRecentFiles:=False, Visible:=False)
        With wdDoc
            With .Range
                With .Find
                    .ClearFormatting
                    .Replacement.ClearFormatting
                    .Text = ChrW(&H649)
                    .Replacement.Text = ""
                    .Forward = True
                    .Wrap = wdFindStop
                    .Format = False
                    .MatchCase = False
                    .MatchWholeWord = False
                    .MatchWildcards = False
                    .MatchSoundsLike = False
                    .MatchAllWordForms = False
                    .Execute
                End With
                Do While .Find.Found
                    i = i + 1
                    WkSht.Cells(i, 1) = Trim(.Duplicate.Words.First.Text)
                    WkSht.Cells(i, 2) = .Duplicate.Information(wdActiveEndAdjustedPageNumber)
                    .Collapse wdCollapseEnd
                    .Find.Execute
                Loop
            End With
            .Close SaveChanges:=False
        End With
        strFile = Dir()
    Wend
    wdApp.Quit
    Set wdDoc = Nothing: Set wdApp = Nothing: Set WkSht = Nothing
    Application.ScreenUpdating = True
End Sub
 
Function GetFolder() As String
    Dim oFolder As Object
    GetFolder = ""
    Set oFolder = CreateObject("Shell.Application").BrowseForFolder(0, "Choose a folder", 0)
    If (Not oFolder Is Nothing) Then GetFolder = oFolder.Items.Item.Path
    Set oFolder = Nothing
End Function
In addition to listing the words, the macro also outputs the pages on which they appear. No attempt is made to check for or remove duplicates.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
copy a specific words to excel list Find specific rows then copy and paste to new doc konopca Word VBA 5 02-20-2014 02:34 PM
copy a specific words to excel list How to allow specific double words in spellcheck Wyndham Word 5 02-06-2014 10:44 AM
copy a specific words to excel list Need VBA For Macro On How To Remove Specific Words netchie Word VBA 6 08-28-2012 03:37 PM
copy a specific words to excel list Macro to copy specific columns in Excel from another spreadsheet KD999 Excel Programming 1 07-20-2012 08:58 AM
copy a specific words to excel list Macro for highlighting specific number of words icsjohn Word VBA 2 12-07-2011 06:44 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 02:28 PM.


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