Solved

Unique word identification in excel documents

Posted on 2014-01-15
4
353 Views
Last Modified: 2014-01-16
I am looking for a macro that can take an excel spreadsheet and generate a text file containing a list of UNIQUE words used in the spreadsheet. Some spreadsheets can contain as many as 80,000 words....

Note: individual cells can have multiple words separated by spaces.

A sample input files is attached

Thank you!
OFX-2.1.1.txt
0
Comment
Question by:cyber-33
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 35

Expert Comment

by:[ fanpages ]
ID: 39784498
Hi,

Sorry, I'm confused by your attached file.

Is this a text file you wish to open in MS-Excel & then produce another text file containing the unique words, or is this the resultant file after the required process is complete?

Perhaps you could attach an example MS-Excel workbook instead, so that it is clear what is required.

Thanks.

BFN,

fp.
0
 
LVL 50

Accepted Solution

by:
Rgonzo1971 earned 500 total points
ID: 39784794
Hi,

pls try this

The macro will ask for the file and then process it and paste the result in the active sheet

Sub macro()

    Const wdDoNotSaveChanges = 0
    
    Set wdApp = CreateObject("Word.Application")
    Dim fd As Object
    Dim Dict As Object
    Set Dict = CreateObject("Scripting.Dictionary")

    Set fd = wdApp.FileDialog(msoFileDialogOpen)
    With fd
        .Filters.Clear
        .Filters.Add "text (*.txt)", "*.txt"
        Result = .Show
        If Result = False Then Exit Sub
        Set wdDoc = wdApp.Documents.Open(Filename:=.SelectedItems(1))
    End With
    
    For Each aword In wdDoc.Words
        SingleWord = Trim(LCase(aword))
        If Not (Left(SingleWord, 1) < "a") And Not (Left(SingleWord, 1) > "z") Then
            If Not Dict.Exists(SingleWord) Then
                Dict.Add SingleWord, SingleWord
            End If
            
        End If
    Next
    wdDoc.Close wdDoNotSaveChanges
    WordList = Dict.Items
    ActiveSheet.Range("A1").Value = "Word List"
    For Idx = 0 To Dict.Count - 1
        s = WordList(Idx)
        ActiveSheet.Range("A1").Offset(Idx + 1).Value = WordList(Idx)
    Next
    
    ActiveSheet.Sort.SortFields.Clear
    ActiveSheet.Sort.SortFields.Add Key:=Range(Range("A2"), Range("A2").End(xlDown)), _
    SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    With ActiveSheet.Sort
        .SetRange Range(Range("A1"), Range("A1").End(xlDown))
        .Header = xlYes
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
    MsgBox "Done"
    
    Set wdApp = Nothing
    Set Dict = Nothing


End Sub

Open in new window

Regards
0
 

Author Closing Comment

by:cyber-33
ID: 39787017
Thank you!
0
 
LVL 35

Expert Comment

by:[ fanpages ]
ID: 39787308
You're welcome.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Excel If Statement 3 29
Need to combine three formulas into one 5 39
Calculate number of months in Excel 13 28
why cannot i download this excel file? 7 29
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question