Solved

Unique word identification in excel documents

Posted on 2014-01-15
4
338 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 49

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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Suggested Solutions

Introduction This Article is a follow-up to my Mappit! Addin Article (http://www.experts-exchange.com/A_2613.html), it was inspired by an email posting I made to EUSPRIG (http://www.eusprig.org/index.htm), I will briefly cover: 1) An overvie…
Introduction While answering a recent question (http:/Q_27311462.html), I created an alternative function to the Excel Concatenate() function that you might find useful.  I tested several solutions and share the results in this article as well as t…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

777 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