473,387 Members | 1,592 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,387 software developers and data experts.

Find Text And Replace Entire Line in Notepad with New Text

Hi,

I have a notepad and I want to find a text into notepad.
Once I find the text in notepad then I want to replace entire line with new text.
This I want to do using Excel VBA.

I have written a code that searches in a file but replaces only the text which it finds but not the entire line.

Below is my code
Expand|Select|Wrap|Line Numbers
  1. Open folderPath & "\XXXX_VARIABLE.txt" For Input As iFile2
  2.             text = Input$(LOF(1), iFile2)
  3.             arr = Split(text, vbNewLine)
  4.         Close iFile2
  5.         iFile2 = FreeFile
  6.         Open folderPath & "\XXXX_VARIABLE.txt" For Output As iFile2
  7.         For Each item In arr
  8.             line = Replace(CStr(item), SrchString, ReplString, 1)
  9.  
  10.             Print #iFile2, line
  11.         Next
  12.         Close iFile2
  13.  
Mar 20 '14 #1
2 2450
Rabbit
12,516 Expert Mod 8TB
This thread has been moved to the Excel forum.

You need to look for the string you want and then print out your replacement text. You can't use the Replace function.
Mar 20 '14 #2
Luuk
1,047 Expert 1GB
"I have a notepad and I want to find a text into notepad."

Better, more correct, would be:
I have a text file in which i want to find a text

Notepad is a program which can be used to open/edit text files.
Mar 22 '14 #3

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

Similar topics

19
by: rbt | last post by:
Here's the scenario: You have many hundred gigabytes of data... possible even a terabyte or two. Within this data, you have private, sensitive information (US social security numbers) about your...
2
by: Daniel | last post by:
I use an Access database to basically take data exports, import them, manipulate the data, and then turn them into exportable reports. I do this using numerous macros, and queries to get the data...
1
by: Karen | last post by:
I am very new to MySQL- I currently have an VBA module using a VBSCript that will find different aspects of a text string that are a unique text string and turn it into a not so unique text string....
2
by: rengask | last post by:
I got the code to find and replace within an open text file. ------------------ Private Sub cmdFile_Click() Dim strTemp As String txtFile = "" dlg.FileName = "*.*" dlg.ShowOpen ...
2
by: nater | last post by:
Hi, I want to write a program to find and replace the block of text in the Oracle CLOB field. The table has more than 50,000 records. Please let me know if you have any suggestions. Thank you..
2
by: santhescript01 | last post by:
Hi everyone, I got a macro that performs a find and replace function on a text.It's working fine but for some unicode character it replaces with weird character despite of original text character. ...
1
by: Jetean | last post by:
Hi: If I have text as below in a Text file "Sample.txt": <STX>jjjjjjjjjjjjjjjjjjjjjjjjjjj<ETX> <STX>hhhhhhhhhhhhhhhhhh<ETX> <STX>666666666666666666666666<ETX>...
0
by: SLDenman | last post by:
I am working on a project and have come to a hault. I am not sure how to code the stings for the Find and Replace function of a notepad that I have created. How do I code to have the input on a...
1
by: Marko Danilovic | last post by:
I need to open some HTML file, then replace exact line of text with another, and then WITHOUT SAVING THE FILE (WriteAllLines(HTML01, lines)) to display in WebBrowser. My code in private sub of...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.