Parsing a text file over multiple lines

RDaniells

New Member
Joined
Oct 27, 2012
Messages
2
I am relatively new to working in vba so bear with me.

I am writing a macro to search a text file for a string "ioelp". Once i find this string i want to read the file until i find the character ";".

I would then like to write the whole string to a new text file.

I then need to take this string and replace a related string in a 3 rd file (this pat i have solved)

Any help would be much appreciated
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Hi and welcome to the forum.

Try something like this...

Code:
    [color=darkblue]Dim[/color] FF [color=darkblue]As[/color] [color=darkblue]Integer[/color]
    [color=darkblue]Dim[/color] strText [color=darkblue]As[/color] [color=darkblue]String[/color]
    
    [color=green]'Read text file[/color]
    FF = FreeFile()
    [color=darkblue]Open[/color] "C:\MyFile.txt" [color=darkblue]For[/color] [color=darkblue]Input[/color] [color=darkblue]As[/color] #FF
    strText = Input$(LOF(FF), FF)
    [color=darkblue]Close[/color] #FF
    
    [color=green]'Parse text[/color]
    strText = Mid(strText, InStr(1, strText, "ioelp", 1))
    strText = Left(strText, InStr(1, strText, ";", 1))
    
    [color=green]'Write parsed text to text file[/color]
    FF = FreeFile()
    [color=darkblue]Open[/color] "C:\Parsed.txt" [color=darkblue]For[/color] [color=darkblue]Output[/color] [color=darkblue]As[/color] #FF
    [color=darkblue]Print[/color] #FF, strText
    [color=darkblue]Close[/color] #FF
 
Upvote 0

Forum statistics

Threads
1,216,746
Messages
6,132,476
Members
449,729
Latest member
davelevnt

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