Thread Tools Display Modes
  #1   Report Post  
mohanjackie mohanjackie is offline
Junior Member
Posts: 0
Exclamation Unhappy Find list of words occurred

I am week in creating macro
I tried all sort of ideas and add-ins, I couldn't find the solution

How can i find list of word occurred in doc(Microsoft word)

List of word is in excel A row


i am tiger
The wolf

So, the macro needs to find number of times this keywords occurred in the article situated in doc in the same folder

I found a code while searching google, but it only stats true or false
  #2   Report Post  
mohanjackie mohanjackie is offline
Junior Member
Posts: 0

This problem solved in another fourm

i am sharing it in the purpose of any other seekers can make use of it.

This the vba i was looking for, both works good

Thanks to karedog and sktneer for this wonderful code specially used for seo purpose

VBA 1 by:karedog

Sub Test()
  Dim a, i As Long, strContent As String
  With CreateObject("Word.Application")
    With .Documents.Open(ThisWorkbook.Path & "\doc.docx")
      strContent = .Content.Text
    End With
  End With
  With Sheets("Keyword Tool Export - Check Sea").Range("A1").CurrentRegion
    a = .Value
    With CreateObject("VBScript.RegExp")
      .Global = True
      .IgnoreCase = True
      For i = 2 To UBound(a, 1)
          .Pattern = Replace$(a(i, 1), ".", "\.")
          If .Test(strContent) Then a(i, 2) = .Execute(strContent).Count
      Next i
    End With
    .Value = a
  End With 
End Sub
VBA 2 by: sktneer

Sub WordCount() 
    Dim SelectedFile As String 
    Dim wdApp As Object 
    Dim Doc As Object 
    Dim WordToCount As String 
    Dim Cnt As Integer, lr As Long 
    Dim Rng As Range, Cell As Range 
    Application.ScreenUpdating = False 
    With Application.FileDialog(msoFileDialogFilePicker) 
        .Title = "Select The Word Document!" 
        .ButtonName = "Confirm" 
        .Filters.Add "Word Documents", "*.docx" 
        If .Show = -1 Then 
            SelectedFile = .SelectedItems(1) 
            MsgBox "You didn't select a document.", vbExclamation, "Document Not Selected!" 
            Exit Sub 
        End If 
    End With 
    lr = Cells(Rows.Count, 1).End(xlUp).Row 
    Set Rng = Range("A2:A" & lr) 
    Set wdApp = CreateObject("Word.Application") 
    Set Doc = wdApp.documents.Open(SelectedFile) 
    For Each Cell In Rng 
        Cnt = 0 
        With wdApp.Selection 
            .HomeKey Unit:=6 
            With .Find 
                .Text = Cell.Value 
                Do While .Execute 
                    Cnt = Cnt + 1 
            End With 
        End With 
        Cell.Offset(0, 1).Value = Cnt 
    Next Cell 
    Application.ScreenUpdating = True 
    Set Doc = Nothing 
    Set wdApp = Nothing 
    MsgBox "Task completed.", vbInformation, "Done!" 
End Sub
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I find duplicated words in a list in Word? Suebob1 Microsoft Word Help 4 July 7th 09 03:31 PM
I would like to find and replace a list of words with numbers checkQ Microsoft Word Help 6 October 2nd 08 07:39 PM
I would like to find and rplace a list of words with code numbers checkQ Microsoft Word Help 0 September 30th 08 07:42 PM
How can I find if there are doubles in my list of words? Rhen Microsoft Word Help 3 June 9th 05 05:12 AM
how do I find repeating words in a list wendyp Microsoft Word Help 5 June 4th 05 06:52 PM

All times are GMT +1. The time now is 03:35 PM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright 2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.

About Us

"It's about Microsoft Word"