Word count from word document into a cell in excel

L

Laebrye

Hi everybody,

I'm trying to do something very specific with absolutely no luck. All I want
to do is find a way of putting the word count from a word file into a cell in
an excel file. Ideally, I'd like a way of updating the the wordcount to a
different cell in the same worksheet each time I perform the macro (I'm
guessing it will have to be a macro, I can't find another way fo doing it.

Any help I can get would be appreciated.

Laebrye
 
F

fumei via OfficeKB.com

So what have you tried so far?

" I can't find another way fo doing it."

Doing what?

Getting the word count?
Getting the word count value into Excel?

What can't you find a way of doing? And what have you tried so far?
 
J

Justin

Doug,

I am trying to accomplish the same thing as Laebrye. Essentially, I am
hoping to produce an Excel spreadsheet which contains word counts for a list
of documents, in order to help with layout for a publication. I have no
familiarity with macros or VBA, and the link you had pointed out was a bit
beyond my understanding. Any suggestions?

-J
 
D

Doug Robbins - Word MVP

The following code will let you select a folder containing the documents and
then it will create a table in a Word document that contains the document
names in one column and the numbe of words in each document in a second
column.

Dim myFile As String
Dim PathToUse As String
Dim myDoc As Document
Dim Response As Long
Dim Target As Document
Dim TargetTable As Table
Dim drow As Row
Dim fd As FileDialog
Set fd = Application.FileDialog(msoFileDialogFolderPicker)
With fd
If .Show = -1 Then
PathToUse = .SelectedItems(1) & "\"
Else
End If
End With
Set fd = Nothing
MsgBox PathToUse
If Len(PathToUse) = 0 Then
Exit Sub
End If
myFile = Dir$(PathToUse & "*.doc")
Set Target = Documents.Add
Set TargetTable = Target.Tables.Add(Target.Range, 1, 2)
With TargetTable
.Cell(1, 1).Range.Text = "Document"
.Cell(1, 2).Range.Text = "Word Count"
End With
While myFile <> ""
Set myDoc = Documents.Open(PathToUse & myFile)
Set drow = TargetTable.Rows.Add
drow.Cells(1).Range.Text = myDoc.Name
drow.Cells(2).Range.Text = myDoc.Words.Count
myDoc.Close SaveChanges:=wdSaveChanges
myFile = Dir$()
Wend

You can copy and paste the table into Excel if that is where you really need
the information.

If you do not know what to do with the above code, see the article "What do
I do with macros sent to me by other newsgroup readers to help me out?" at:

http://www.word.mvps.org/FAQs/MacrosVBA/CreateAMacro.htm


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
J

Justin

Thanks, Doug! That works really well. I added a second column to
incorporate character count, as word count alone for layouts can often be
misleading.

One problem that I ran into, however, was that this iteration of the macro
does not take into account the presence of endnotes or footnotes. Any
suggestions on how to tweak it?

Again, thanks so much for your help!
 
D

Doug Robbins - Word MVP

You would need to iterate through the StoryRanges in the document and add
the totals from each. For some information on iterating through the
StoryRanges, see the article "Using a macro to replace text where ever it
appears in a document including Headers, Footers, Textboxes, etc." at:

http://www.word.mvps.org/FAQs/MacrosVBA/FindReplaceAllWithVBA.htm




--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
N

Neha Verma

I am facing one problem i have a word file which contain some text as well as images my task is to count the number of words and paragraphs from that text file and display the count in an excel sheet i have created a macro which count the words and paragraphs in a word file but i want the same output in some excel file. Please help me its urgent..
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top