+ Reply to Thread
Results 1 to 5 of 5

VBA Macro to search document for specific keyword/phrases

  1. #1
    Registered User
    Join Date
    11-16-2014
    Location
    New York
    MS-Off Ver
    2011
    Posts
    25

    VBA Macro to search document for specific keyword/phrases

    :::NEWB Status:::
    ::NEWB STATUS:::

    So I have this macro;
    Sub FindWords()
    Dim sResponse As String
    Dim iCount As Integer

    ' Input different words until the user clicks cancel
    Do
    ' Identify the word to count
    sResponse = InputBox( _
    Prompt:="What is the word or phrase you wish to evaluate?", _
    Title:="ASR Keywords", Default:="")

    If sResponse > "" Then
    ' Set the counter to zero for each loop
    iCount = 0
    Application.ScreenUpdating = False
    With Selection
    .HomeKey Unit:=wdStory
    With .Find
    .ClearFormatting
    .Text = sResponse
    ' Loop until Word can no longer
    ' find the search string and
    ' count each instance
    Do While .Execute
    iCount = iCount + 1
    Selection.MoveRight
    Loop
    End With
    ' show the number of occurences
    MsgBox sResponse & " is in the file " & iCount & " times"
    End With
    Application.ScreenUpdating = True
    End If
    Loop While sResponse <> ""
    End Sub

    The thing i'm trying to do is take the number value that the MsgBox shows and put it next to the Keyword/phrase (See Excel sheet). Basically i'm creating my own ATS for resumes and I have a list of keywords that I want to know the number of occurrence in a particular resume file (I put entire resume in A3 in the example spreadsheet attached. There's got to be a better way!). (Naturally, I'm going to add other rules to rate each keywords presence, but the rest of the algorithm I am doing by chaining clever excel functions together)
    I know how to make the iCount + 1 show in the MsgBox, but the text in the message box isn't highlighting capable. Can i just put the value and record a macro or something?
    Any help on here is usually rather excellent so Ill certainly give you some good feedback.
    Attached Files Attached Files
    Last edited by Apcal88; 02-20-2015 at 03:56 PM.

  2. #2
    Forum Expert newdoverman's Avatar
    Join Date
    02-07-2013
    Location
    Port Dover, Ontario, Canada
    MS-Off Ver
    2010
    Posts
    10,330

    Re: VBA Macro to search document for specific keyword/phrases

    First of all, please take note of the following:

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here



    (This thread should receive no further responses until this moderation request is fulfilled, as per Forum Rule 7)

    I don't know if what you want can be done or not with VBA but a VBA expert should be able to help in that regard after you make the changes and surround the macro code with the code tags.
    <---------If you like someone's answer, click the star to the left of one of their posts to give them a reputation point for that answer.
    Ron W

  3. #3
    Registered User
    Join Date
    11-16-2014
    Location
    New York
    MS-Off Ver
    2011
    Posts
    25

    Re: VBA Macro to search document for specific keyword/phrases

    Gotcha. I suppose I broke #4 too. Unfortunately, being the newb that I am..i'm not sure I can see anything other than the BOLD. I suppose we can't win them all. Thanks for your time, though!
    My code is as follows:

    Sub FindWords()
    Dim sResponse As String
    Dim iCount As Integer

    ' Input different words until the user clicks cancel
    Do
    ' Identify the word to count
    sResponse = InputBox( _
    Prompt:="What is the word or phrase you wish to evaluate?", _
    Title:="ASR Keywords", Default:="")

    If sResponse > "" Then
    ' Set the counter to zero for each loop
    iCount = 0
    Application.ScreenUpdating = False
    With Selection
    .HomeKey Unit:=wdStory
    With .Find
    .ClearFormatting
    .Text = sResponse
    ' Loop until Word can no longer
    ' find the search string and
    ' count each instance
    Do While .Execute
    iCount = iCount + 1
    Selection.MoveRight
    Loop
    End With
    ' show the number of occurences
    MsgBox sResponse & " is in the file " & iCount & " times"
    End With
    Application.ScreenUpdating = True
    End If
    Loop While sResponse <> ""
    End Sub

    Have a great one all!

  4. #4
    Forum Expert newdoverman's Avatar
    Join Date
    02-07-2013
    Location
    Port Dover, Ontario, Canada
    MS-Off Ver
    2010
    Posts
    10,330

    Re: VBA Macro to search document for specific keyword/phrases

    When you use code tags the code should show up like this which makes it easy to select and copy by those who want to work with the code.

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    11-16-2014
    Location
    New York
    MS-Off Ver
    2011
    Posts
    25

    Re: VBA Macro to search document for specific keyword/phrases

    ah HA! I sort of did the same thing, but I figured that since the spreadsheet would be static having the word doc open the excel file. Well played, Sir!
    For the Google searchers out there; This is a decent answer for having a VBA search a word document and report the number of times a set of specific words/phrases appear.

    Please Login or Register  to view this content.
    Last edited by Apcal88; 02-20-2015 at 04:37 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Excel macro to add html tags to specific phrases in one worksheet
    By terryhenderson in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-18-2014, 08:49 AM
  2. [SOLVED] keyword search - a macros to change font color for specific key words (not entire cell)
    By kingwhopper in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 05-10-2014, 12:25 PM
  3. Replies: 6
    Last Post: 03-18-2014, 11:16 AM
  4. Search for workbook in specific directory, based on keyword
    By GeorgY in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-10-2009, 11:15 PM
  5. Sorting Keyword Phrases
    By rpgun in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-12-2005, 03:15 PM

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