Searching many text files for a string

Wyattwic

New Member
Joined
Feb 15, 2018
Messages
2
Hello everyone! I'm new to the forums and my first post is a question post, sorry! It's nice to meet y'all!

I am stumped on how to do this, any assistance would be appreciated.

I have a folder containing 50-200 text files. In my excel document, I need to return a count of how many times a specific string occurred in those text files. I have about 50 different strings I need to get a count on.

How I am currently processing this is using notepad++'s search in files feature. I would search for the string inside the folder, then copy down the total results.

Assistance would be appreciated! Thank you!!
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Hello,

a possible way is to use the cmd find-function:

Code:
open the cmd-window
navigate to the folder
to find all "Hello" 
find /C "Hello" *.txt

If one trial is fine, it is possible to start (and loop though all search-word with xl-vba.

regards
 
Upvote 0
Hello again,

from my archiv:

Code:
Sub snb_find()
'sucht Text in Dateien
'Suchtext in " ", z.b. "Merkmal"
  sn = Split(CreateObject("wscript.shell").exec("cmd /c find  /N ""search-word"" c:\temp\*.txt ").stdout.readall, vbCrLf)

For Each d In sn
    Debug.Print d
  Next d
  
End Sub

The path, here c:\temp, must be adopted. And, a bit work on your side, the search-word must become flexible, a word from the sheet.

Pease try /n as well as /c

regards
 
Upvote 0
Thanks Fennek! I'm completely alien to visual basic, but those code examples look to be exactly what I need.

Once I have a final product, I'll post it back here.
 
Upvote 0

Forum statistics

Threads
1,223,901
Messages
6,175,277
Members
452,629
Latest member
SahilPolekar

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top