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
Bookmarks