Hi Team,
What could be done in case where i want to count words of a bunch of document in folder and also required output in excel file.
I have something that i found from some where.
Sub ListWordCount()
'In the Visual Basic Editor,
'go to Tools -> References and check the box for
'Microsoft Scripting Runtime to access the
'filesystem object.
Dim fso As Scripting.FileSystemObject
Dim fol As Scripting.Folder
Dim cfil As Variant
Dim fil_1 As Scripting.File
Dim s As String
'The FSO isn't the fastest object in existence
'and much slower than using the Windows API (or its
'VB.Net namesake for that matter) but it's convenient
'and easy to use.
Set fso = New FileSystemObject
Set fol = fso.GetFolder("C:\Users\harshadp\Desktop\New folder (2)")
Set cfil = fol.Files
'Helps it run a bit faster...
Application.ScreenUpdating = True
For Each fil_1 In cfil
Select Case fil_1.Type
'Add any other types that you want to check for
Case "Microsoft Word 97 - 2003 Document", "Microsoft Word Document"
Documents.Open FileName:=fil_1.path
Debug.Print fil_1.Name & vbTab & _
ActiveDocument.Range.ComputeStatistics(wdStatisticWords) _
& " words."
Documents.Close savechanges:=False
End Select
Next
ExitPoint:
On Error Resume Next
Set fil_1 = Nothing
Set cfil = Nothing
Set fol = Nothing
Set fso = Nothing
Application.ScreenUpdating = True
Application.ScreenRefresh
On Error GoTo 0
Exit Sub
ErrorHandler:
MsgBox Err.Number & vbCr & Err.Description
Resume ExitPoint
End Sub
This macro runs fine in word givign error in excel
Bookmarks