Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Unique word identification in excel documents

Posted on 2014-01-15
4
Medium Priority
?
365 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
  • 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 53

Accepted Solution

by:
Rgonzo1971 earned 2000 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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
After seeing numerous questions for Dynamic Data Validation I notice that most have used Visual Basic to solve the problem. This suggestion is purely formula based and can be used in multiple rows.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

824 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