Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
Word
application.errors
conversions
docmanagement
drawing.graphics
formatting.longdocs
international
internet.assistant
mail
mailmerge.fields
menustoolbars
newusers
numbering
oleinterop
pagelayout
printingfonts
setup.networking
spelling.grammar
tables
vba.addins
vba.beginners
vba.customization
vba.general
vba.userforms
web.authoring
word6-7macros
word97vba
  
 
date: Fri, 3 Oct 2008 08:49:02 -0700,    group: microsoft.public.word.vba.general        back       


Word count from word document into a cell in excel   
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
date: Fri, 3 Oct 2008 08:49:02 -0700   author:   Laebrye

Re: Word count from word document into a cell in excel   
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?

Laebrye wrote:
>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

-- 
Message posted via http://www.officekb.com
date: Fri, 03 Oct 2008 17:24:14 GMT   author:   fumei via OfficeKB.com u37563@uwe

Re: Word count from word document into a cell in excel   
See the article "Control Excel from Word" at:

http://www.word.mvps.org/FAQs/InterDev/ControlXLFromWord.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

"Laebrye"  wrote in message 
news:EA543315-985D-41B3-A1B6-AE1AB3600CD0@microsoft.com...
> 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
date: Sat, 4 Oct 2008 18:55:34 +1000   author:   Doug Robbins - Word MVP

Re: Word count from word document into a cell in excel   
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 

"Doug Robbins - Word MVP" wrote:

> See the article "Control Excel from Word" at:
> 
> http://www.word.mvps.org/FAQs/InterDev/ControlXLFromWord.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
> 
> "Laebrye"  wrote in message 
> news:EA543315-985D-41B3-A1B6-AE1AB3600CD0@microsoft.com...
> > 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 
> 
> 
>
date: Tue, 18 Nov 2008 11:50:11 -0800   author:   Justin

Re: Word count from word document into a cell in excel   
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

"Justin"  wrote in message 
news:4F48BB2B-0A78-473B-B7F2-BB4354C778AA@microsoft.com...
> 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
>
> "Doug Robbins - Word MVP" wrote:
>
>> See the article "Control Excel from Word" at:
>>
>> http://www.word.mvps.org/FAQs/InterDev/ControlXLFromWord.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
>>
>> "Laebrye"  wrote in message
>> news:EA543315-985D-41B3-A1B6-AE1AB3600CD0@microsoft.com...
>> > 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
>>
>>
>>
date: Wed, 19 Nov 2008 20:07:48 +1000   author:   Doug Robbins - Word MVP

Re: Word count from word document into a cell in excel   
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!

"Doug Robbins - Word MVP" wrote:

> 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
> 
> "Justin"  wrote in message 
> news:4F48BB2B-0A78-473B-B7F2-BB4354C778AA@microsoft.com...
> > 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
> >
> > "Doug Robbins - Word MVP" wrote:
> >
> >> See the article "Control Excel from Word" at:
> >>
> >> http://www.word.mvps.org/FAQs/InterDev/ControlXLFromWord.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
> >>
> >> "Laebrye"  wrote in message
> >> news:EA543315-985D-41B3-A1B6-AE1AB3600CD0@microsoft.com...
> >> > 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
> >>
> >>
> >> 
> 
> 
>
date: Wed, 19 Nov 2008 14:49:02 -0800   author:   Justin

Re: Word count from word document into a cell in excel   
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

"Justin"  wrote in message 
news:B353F718-AE61-4EAF-A1D8-C5F928CD410C@microsoft.com...
> 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!
>
> "Doug Robbins - Word MVP" wrote:
>
>> 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
>>
>> "Justin"  wrote in message
>> news:4F48BB2B-0A78-473B-B7F2-BB4354C778AA@microsoft.com...
>> > 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
>> >
>> > "Doug Robbins - Word MVP" wrote:
>> >
>> >> See the article "Control Excel from Word" at:
>> >>
>> >> http://www.word.mvps.org/FAQs/InterDev/ControlXLFromWord.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
>> >>
>> >> "Laebrye"  wrote in message
>> >> news:EA543315-985D-41B3-A1B6-AE1AB3600CD0@microsoft.com...
>> >> > 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
>> >>
>> >>
>> >>
>>
>>
>>
date: Thu, 20 Nov 2008 16:13:44 +1000   author:   Doug Robbins - Word MVP

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us