Results 1 to 11 of 11

VBA to Count Words in MS Word Doc and List Down it in excel

Threaded View

  1. #1
    Registered User
    Join Date
    06-17-2013
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    2

    VBA to Count Words in MS Word Doc and List Down it in excel

    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
    Last edited by harshadp; 06-18-2013 at 11:41 AM. Reason: Use code tags as per forum rule 3.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1