Results 1 to 5 of 5

How to open a Word.doc using VBA and count the words in the word.doc?

Threaded View

  1. #1
    Registered User
    Join Date
    10-31-2007
    Posts
    5

    How to open a Word.doc using VBA and count the words in the word.doc?

    I have problem writing a code to open a word.doc and count the different number of words in the doc. my code is as follows. Can anyone tell me what is the prob?

     
    Sub automateword()
    
    
        Set wordapp = CreateObject("word.Application")
    
    
        wordapp.Documents.Open "C:\Documents and Settings\Admin\Desktop\letter.doc"
        
        wordapp.Visible = True
    
    Dim totalwords As Long
    
    totalwords = Activeworksheet.Words.Count
    
    Dim i As Long, Word As Range, str As String, j As Long, f As Integer
    
    Dim arr() As String
    
    
    For Each Word In ActiveDocument.Words
        For i = 1 To totalwords Step 1
        f = 0
            For j = i To totalwords Step 1
         If arr(i) = arr(j) Then
         f = f + 1
          Range("A1").Offset(i, 0).Value = Word
          Range("B1").Offset(i, 0).Value = f
        End If
        Next
        
        
        Next
    Next
    
    End Sub
    Last edited by VBA Noob; 11-01-2007 at 03:11 AM.

Thread Information

Users Browsing this Thread

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

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