PC Review


Reply
Thread Tools Rate Thread

How to count all words in more document W2007

 
 
=?Utf-8?B?SmFuIEtyYXRvY2h2aWw=?=
Guest
Posts: n/a
 
      1st Aug 2007
I have this macro but some funcionality is deprecated for W2007.
Have you any suggestion how to make it in other way?


Sub CountAllWords()
'2007 David Sisson
' not suported for W2007 Application.FileSearch deprecated
Dim aDoc As Document
Dim bDoc As Document
Dim sFolderToLookIn As String
Dim TotalWords As Integer
Dim DocWordsCount As Integer
Dim X As Integer

Set bDoc = ActiveDocument
sFolderToLookIn = "C:\My Documents\CountingFolder"
With Application.FileSearch
.NewSearch
.FileName = "*.doc"
.LookIn = sFolderToLookIn
.Execute
For X = 1 To .FoundFiles.Count
Application.ScreenUpdating = False
Set aDoc = Documents.Open(.FoundFiles(X))
DocWordsCount = aDoc.ComputeStatistics(Statistic:=wdStatisticWords, _
IncludeFootnotesAndEndnotes:=True)

bDoc.Range.InsertAfter .FoundFiles(X) & " - " & DocWordsCount & vbCr
TotalWords = TotalWords + DocWordsCount
aDoc.Close savechanges:=wdDoNotSaveChanges
Next X

bDoc.Range.InsertAfter TotalWords & " Total words in " & X & "documents."
End With
Application.ScreenUpdating = True
End Sub

--
Regards
Jan Kratochvil
WIN XP Pro SP2, Office 2007
 
Reply With Quote
 
 
 
 
Graham Mayor
Guest
Posts: n/a
 
      1st Aug 2007
I posted a macro to do this last time you asked about it. That macro put the
word count in a message box. If you want it in a document then see below. I
have also put in the same count routine that David Sissons offered, though
it gives the same answers. Neither counts text in the header/footer. The
macro will close (giving you the opportunity to save) any open documents
before running on the folder you select. This does work in Word 2007 or
2003.

Sub Test2()
Dim myFile As String
Dim PathToUse As String
Dim MyDoc As Document
Dim wdCount As Integer
Dim docCount As Integer

wdCount = 0
docCount = 0
With Dialogs(wdDialogCopyFile)
If .Display <> 0 Then
PathToUse = .Directory
Else
MsgBox "Cancelled by User"
Exit Sub
End If
End With
If Documents.Count > 0 Then
Documents.Close SaveChanges:=wdPromptToSaveChanges
End If
If Left(PathToUse, 1) = Chr(34) Then
PathToUse = Mid(PathToUse, 2, Len(PathToUse) - 2)
End If
myFile = Dir$(PathToUse & "*.do*")
While myFile <> ""
Set MyDoc = Documents.Open(PathToUse & myFile)
docCount = docCount + 1
'wdCount = wdCount + MyDoc.BuiltInDocumentProperties(wdPropertyWords)
wdCount = wdCount + MyDoc.ComputeStatistics(Statistic:=wdStatisticWords, _
IncludeFootnotesAndEndnotes:=True)
MyDoc.Close SaveChanges:=wdDoNotSaveChanges
myFile = Dir$()
Wend
Documents.Add
Selection.TypeText wdCount & " in " & docCount & " documents"
End Sub



--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

Jan Kratochvil wrote:
> I have this macro but some funcionality is deprecated for W2007.
> Have you any suggestion how to make it in other way?
>
>
> Sub CountAllWords()
> '2007 David Sisson
> ' not suported for W2007 Application.FileSearch deprecated
> Dim aDoc As Document
> Dim bDoc As Document
> Dim sFolderToLookIn As String
> Dim TotalWords As Integer
> Dim DocWordsCount As Integer
> Dim X As Integer
>
> Set bDoc = ActiveDocument
> sFolderToLookIn = "C:\My Documents\CountingFolder"
> With Application.FileSearch
> .NewSearch
> .FileName = "*.doc"
> .LookIn = sFolderToLookIn
> .Execute
> For X = 1 To .FoundFiles.Count
> Application.ScreenUpdating = False
> Set aDoc = Documents.Open(.FoundFiles(X))
> DocWordsCount =
> aDoc.ComputeStatistics(Statistic:=wdStatisticWords, _
> IncludeFootnotesAndEndnotes:=True)
>
> bDoc.Range.InsertAfter .FoundFiles(X) & " - " & DocWordsCount
> & vbCr TotalWords = TotalWords + DocWordsCount
> aDoc.Close savechanges:=wdDoNotSaveChanges
> Next X
>
> bDoc.Range.InsertAfter TotalWords & " Total words in " & X &
> "documents." End With
> Application.ScreenUpdating = True
> End Sub



 
Reply With Quote
 
=?Utf-8?B?SmFuIEtyYXRvY2h2aWw=?=
Guest
Posts: n/a
 
      2nd Aug 2007
I inserted the macro in my template but I can't get the Msg Box with result.

Here is the test template I tried to use:
http://www.flashmedia.cz/test/test_tpl.dot

The macro did following:

It opens directory
I select directory and click open
Document will be closed.
Than nothing happen.
I can't see the Msg Box.

Thank you




--
Regards
Jan Kratochvil
WIN XP Pro SP2, Office 2007


"Graham Mayor" wrote:

> I posted a macro to do this last time you asked about it. That macro put the
> word count in a message box. If you want it in a document then see below. I
> have also put in the same count routine that David Sissons offered, though
> it gives the same answers. Neither counts text in the header/footer. The
> macro will close (giving you the opportunity to save) any open documents
> before running on the folder you select. This does work in Word 2007 or
> 2003.
>
> Sub Test2()
> Dim myFile As String
> Dim PathToUse As String
> Dim MyDoc As Document
> Dim wdCount As Integer
> Dim docCount As Integer
>
> wdCount = 0
> docCount = 0
> With Dialogs(wdDialogCopyFile)
> If .Display <> 0 Then
> PathToUse = .Directory
> Else
> MsgBox "Cancelled by User"
> Exit Sub
> End If
> End With
> If Documents.Count > 0 Then
> Documents.Close SaveChanges:=wdPromptToSaveChanges
> End If
> If Left(PathToUse, 1) = Chr(34) Then
> PathToUse = Mid(PathToUse, 2, Len(PathToUse) - 2)
> End If
> myFile = Dir$(PathToUse & "*.do*")
> While myFile <> ""
> Set MyDoc = Documents.Open(PathToUse & myFile)
> docCount = docCount + 1
> 'wdCount = wdCount + MyDoc.BuiltInDocumentProperties(wdPropertyWords)
> wdCount = wdCount + MyDoc.ComputeStatistics(Statistic:=wdStatisticWords, _
> IncludeFootnotesAndEndnotes:=True)
> MyDoc.Close SaveChanges:=wdDoNotSaveChanges
> myFile = Dir$()
> Wend
> Documents.Add
> Selection.TypeText wdCount & " in " & docCount & " documents"
> End Sub
>
>
>
> --
> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
> Graham Mayor - Word MVP
>
> My web site www.gmayor.com
> Word MVP web site http://word.mvps.org
> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
>
> Jan Kratochvil wrote:
> > I have this macro but some funcionality is deprecated for W2007.
> > Have you any suggestion how to make it in other way?
> >
> >
> > Sub CountAllWords()
> > '2007 David Sisson
> > ' not suported for W2007 Application.FileSearch deprecated
> > Dim aDoc As Document
> > Dim bDoc As Document
> > Dim sFolderToLookIn As String
> > Dim TotalWords As Integer
> > Dim DocWordsCount As Integer
> > Dim X As Integer
> >
> > Set bDoc = ActiveDocument
> > sFolderToLookIn = "C:\My Documents\CountingFolder"
> > With Application.FileSearch
> > .NewSearch
> > .FileName = "*.doc"
> > .LookIn = sFolderToLookIn
> > .Execute
> > For X = 1 To .FoundFiles.Count
> > Application.ScreenUpdating = False
> > Set aDoc = Documents.Open(.FoundFiles(X))
> > DocWordsCount =
> > aDoc.ComputeStatistics(Statistic:=wdStatisticWords, _
> > IncludeFootnotesAndEndnotes:=True)
> >
> > bDoc.Range.InsertAfter .FoundFiles(X) & " - " & DocWordsCount
> > & vbCr TotalWords = TotalWords + DocWordsCount
> > aDoc.Close savechanges:=wdDoNotSaveChanges
> > Next X
> >
> > bDoc.Range.InsertAfter TotalWords & " Total words in " & X &
> > "documents." End With
> > Application.ScreenUpdating = True
> > End Sub

>
>
>

 
Reply With Quote
 
Graham Mayor
Guest
Posts: n/a
 
      2nd Aug 2007
The version of the macro (test2) in this thread writes the count to a new
document.
The earlier one wrote it to a message box.
If you put your template from the web link in the startup folder for Word
2007 m(or open it in Word 2007, to make its macros available, it works as
stated. It opens every document in the selected folder and counts the
documents and the words in them.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

Jan Kratochvil wrote:
> I inserted the macro in my template but I can't get the Msg Box with
> result.
>
> Here is the test template I tried to use:
> http://www.flashmedia.cz/test/test_tpl.dot
>
> The macro did following:
>
> It opens directory
> I select directory and click open
> Document will be closed.
> Than nothing happen.
> I can't see the Msg Box.
>
> Thank you
>
>
>
>
>
>> I posted a macro to do this last time you asked about it. That macro
>> put the word count in a message box. If you want it in a document
>> then see below. I have also put in the same count routine that David
>> Sissons offered, though it gives the same answers. Neither counts
>> text in the header/footer. The macro will close (giving you the
>> opportunity to save) any open documents before running on the folder
>> you select. This does work in Word 2007 or 2003.
>>
>> Sub Test2()
>> Dim myFile As String
>> Dim PathToUse As String
>> Dim MyDoc As Document
>> Dim wdCount As Integer
>> Dim docCount As Integer
>>
>> wdCount = 0
>> docCount = 0
>> With Dialogs(wdDialogCopyFile)
>> If .Display <> 0 Then
>> PathToUse = .Directory
>> Else
>> MsgBox "Cancelled by User"
>> Exit Sub
>> End If
>> End With
>> If Documents.Count > 0 Then
>> Documents.Close SaveChanges:=wdPromptToSaveChanges
>> End If
>> If Left(PathToUse, 1) = Chr(34) Then
>> PathToUse = Mid(PathToUse, 2, Len(PathToUse) - 2)
>> End If
>> myFile = Dir$(PathToUse & "*.do*")
>> While myFile <> ""
>> Set MyDoc = Documents.Open(PathToUse & myFile)
>> docCount = docCount + 1
>> 'wdCount = wdCount + MyDoc.BuiltInDocumentProperties(wdPropertyWords)
>> wdCount = wdCount +
>> MyDoc.ComputeStatistics(Statistic:=wdStatisticWords, _
>> IncludeFootnotesAndEndnotes:=True)
>> MyDoc.Close SaveChanges:=wdDoNotSaveChanges
>> myFile = Dir$()
>> Wend
>> Documents.Add
>> Selection.TypeText wdCount & " in " & docCount & " documents"
>> End Sub
>>
>>
>>
>> --
>> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
>> Graham Mayor - Word MVP
>>
>> My web site www.gmayor.com
>> Word MVP web site http://word.mvps.org
>> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
>>
>> Jan Kratochvil wrote:
>>> I have this macro but some funcionality is deprecated for W2007.
>>> Have you any suggestion how to make it in other way?
>>>
>>>
>>> Sub CountAllWords()
>>> '2007 David Sisson
>>> ' not suported for W2007 Application.FileSearch deprecated
>>> Dim aDoc As Document
>>> Dim bDoc As Document
>>> Dim sFolderToLookIn As String
>>> Dim TotalWords As Integer
>>> Dim DocWordsCount As Integer
>>> Dim X As Integer
>>>
>>> Set bDoc = ActiveDocument
>>> sFolderToLookIn = "C:\My Documents\CountingFolder"
>>> With Application.FileSearch
>>> .NewSearch
>>> .FileName = "*.doc"
>>> .LookIn = sFolderToLookIn
>>> .Execute
>>> For X = 1 To .FoundFiles.Count
>>> Application.ScreenUpdating = False
>>> Set aDoc = Documents.Open(.FoundFiles(X))
>>> DocWordsCount =
>>> aDoc.ComputeStatistics(Statistic:=wdStatisticWords, _
>>> IncludeFootnotesAndEndnotes:=True)
>>>
>>> bDoc.Range.InsertAfter .FoundFiles(X) & " - " & DocWordsCount
>>> & vbCr TotalWords = TotalWords + DocWordsCount
>>> aDoc.Close savechanges:=wdDoNotSaveChanges
>>> Next X
>>>
>>> bDoc.Range.InsertAfter TotalWords & " Total words in " & X &
>>> "documents." End With
>>> Application.ScreenUpdating = True
>>> End Sub



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Word Count for Section in W2007? Amish Microsoft Word New Users 1 5th Jun 2010 04:43 PM
Font sizes not saving (W2007 opening document originally created inW2003) ZephyrAssociates Microsoft Word Document Management 1 19th Dec 2009 03:36 AM
Re: New to W2007 -there appear to be larger spaces between words Suzanne S. Barnhill Microsoft Word Document Management 2 22nd Aug 2008 01:32 PM
Count of words in Word 2007 and count in 2003 are different Gabi Microsoft Word Document Management 2 27th May 2008 12:20 PM
How do I count the number of words in a PowerPoint document? =?Utf-8?B?YWhvb3Rz?= Microsoft Powerpoint 1 26th Apr 2005 03:50 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:09 AM.