473,320 Members | 1,861 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Find and replace in multiple files inside a folder

I got the code to find and replace within an open text file.
------------------

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdFile_Click()
  2.   Dim strTemp As String
  3.  
  4.   txtFile = ""
  5.   dlg.FileName = "*.*"
  6.   dlg.ShowOpen
  7.   If Dir(dlg.FileName) <> "" Then
  8.     Open dlg.FileName For Input As 1
  9.     While Not EOF(1)
  10.       Line Input #1, strTemp
  11.       txtFile = txtFile & strTemp & vbCrLf
  12.     Wend
  13.     Close #1
  14.   Else
  15.     MsgBox "File not found"
  16.   End If
  17. End Sub
  18.  
  19.  
  20. Private Sub cmdFindNext_Click()
  21.   If txtFind <> "" Then
  22.     txtFile.SelStart = txtFile.SelStart + 2
  23.     If InStr(txtFile.SelStart, txtFile, txtFind) <> 0 Then
  24.       txtFile.SelStart = InStr(txtFile.SelStart, txtFile, txtFind) - 1
  25.       txtFile.SelLength = Len(txtFind)
  26.     Else
  27.       MsgBox "Not found"
  28.     End If
  29.   End If
  30. End Sub
  31.  
  32. Private Sub cmdReplace_Click()
  33.   If Len(txtFile.SelText) > 0 Then txtFile.SelText = txtReplace
  34.   cmdFindNext_Click
  35. End Sub
  36.  
  37. Private Sub cmdReplaceAll_Click()
  38.   cmdFindNext_Click
  39.   While Len(txtFile.SelText) > 0
  40.     txtFile.SelText = txtReplace
  41.     cmdFindNext_Click
  42.   Wend
  43. End Sub
-------------
If I want to perform multiple string replacements in multiple files, how do I modify the code. I've decided to put the find strings in column A and strings to be replaced in column B of an excel sheet. I need to search for 1st cell in column A thorughout all the files in a folder and replace with 1st cell (column B) throught the folder.

Please help.
Feb 14 '07 #1
2 3269
willakawill
1,646 1GB
Hi. You need to set up a loop
Feb 15 '07 #2
Killer42
8,435 Expert 8TB
Hi. You need to set up a loop
Also, do a search on TheScripts (or the wider web if necessary) for topics such as "VB Excel automation", as this is what you will need to use for the Excel part.

Um... probably.

It would most likely be simpler if you just code it in an Excel macro, though of course then you need to run it in Excel, which may be a nuisance.
Feb 16 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Cortes | last post by:
Hi all, Suppose I want to add 1 single line: <script src = "/sample.js" type="text/javascript"></script> to every single webpage ( preferrably right after the tag <head>) under the root...
1
by: Xah Lee | last post by:
suppose you want to do find & replace of string of all files in a directory. here's the code: ©# -*- coding: utf-8 -*- ©# Python © ©import os,sys © ©mydir= '/Users/t/web'
9
by: Tom Weston | last post by:
Help I have 4 databases containing different data relating to safety, not written by me. It is not possible to merge the databases into one large data base. I would like to create a user interface...
5
by: Robert Magnusson | last post by:
Hi All, This is sure to be an easy question. I am wondering what the accepted standard is for referencing a sub-folder below the application.exe folder? In VB6 you simply used App.Path and...
4
by: serge | last post by:
I managed to put together C# code and have it do the following: 1- Get all the table names that start with the letter "Z" from sysobjects of my SQL 2000 database and put these table names...
0
by: Xah Lee | last post by:
Interactive Find and Replace String Patterns on Multiple Files Xah Lee, 2006-06 Suppose you need to do find and replace of a string pattern, for all files in a directory. However, you do not...
5
by: anupkossambe | last post by:
Hello guys, I'm working on a code in VB6.0 which involves copying all the files inside a folder to another folder. I have managed to do that but the problem arises when there are subfolders inside...
0
by: vasikaran | last post by:
Hi , i hava one ftp script in batch file programming , ftp script is working fine.. but my is i dont know how much files and what are files avaiulable in remote folder ,,,, if any errors or...
0
by: redAllison21 | last post by:
what i have is a folder that has over 1000 pdf's inside it. I also have a program that runs a querey in SAP and returns a text file with certain pdfs that need to be copied into another folder to be...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.