Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6108547
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:18:27+00:00 2026-05-23T14:18:27+00:00

There are certain text files in a folder, i.e, file1.txt ; file2.txt; … Also,

  • 0

There are certain text files in a folder, i.e, file1.txt ; file2.txt; … Also, there is an array of strings which can be stored as studs(i) in VBScript. My objective is to verify if each string (studs(i)) is present in each of the text file (fileN.txt) and write the information to an excel sheet with the strings elements in the rows and filenames(file1, file2, file3,….) in the columns. I need a Vbscript which automates this process. Any help is greatly appreciated

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T14:18:27+00:00Added an answer on May 23, 2026 at 2:18 pm

    See if this helps

    • execute findstr command
    • capture result in System.Collections.ArrayList
    • result can then be stored in excel

    Code

    Function findFilesThatContain(searchText, filePath)
        Set DataList = CreateObject _
        ("System.Collections.ArrayList")
        Set objShell = WScript.CreateObject("WScript.Shell")
        Set objExecObject = objShell.Exec("findstr /M """ & searchText & """ " & filePath)
        Do While Not objExecObject.StdOut.AtEndOfStream
            fileLoc = objExecObject.StdOut.ReadLine()
            'Wscript.Echo searchText&","&fileLoc      
            DataList.Add fileLoc
        Loop
        Set findFilesThatContain = DataList
    End Function
    
    Sub saveToExcel(searchText, searchPath, strExcelPath)
        Set objExcel = CreateObject("Excel.Application")
        If (Err.Number <> 0) Then
            On Error GoTo 0
            Wscript.Echo "Excel application not found."
            Wscript.Quit
        End If
        objExcel.Workbooks.Add
        Set objSheet = objExcel.ActiveWorkbook.Worksheets(1)
        objSheet.Name = "Search Result"
        Dim i,j
        j = 1
        For Each searchText in searchTexts
            Dim files
            Set files = findFilesThatContain (searchText, searchPath)
            i = 1
            objSheet.Cells(i, j).Value = searchText
            For Each path in files
                Wscript.Echo searchText&","&path
                i = i + 1
                objSheet.Cells(i, j).Value = path
            Next
            j = j + 1
        Next
        objSheet.Range("1:1").Font.Bold = True
        objExcel.ActiveWorkbook.SaveAs strExcelPath, 56
        objExcel.ActiveWorkbook.Close
        objExcel.Application.Quit
    End Sub
    Dim strExcelPath
    strExcelPath = "c:\test.xls"
    Dim searchPath 
    searchPath = "E:\bin\bat\*.bat"
    Dim searchTexts(2)
    searchTexts(0)="pushd"
    searchTexts(1)="if"
    saveToExcel searchText, searchPath, strExcelPath
    

    output

    table

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a way I can write text to a file from a certain
There are certain conditions that can cause stack overflows on an x86 Linux system:
I often work with text files which have a variable amount of whitespaces as
I've just downloaded a bunch of text files from data.gov, and there are fields
Is there a way in eclipse to assign certain files a colour (much like
I am zipping directory which has sub directories and there are few files which
BeyondCompare has this conversion feature which can run an external program on certain file
I have some strings in a text files representing object ids, sometimes the id
For example, are there certain things when writing an operating system that cannot be
In various projects there are certain parts I will keep jumping to. Is there

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.