How to replace a string using vba?

B

bonnie.tangyn

Dear all

I want to replace string which is stored in buffer. For example, the
buffer contains a word student. I want to replace it by teacher.

I used the following code to read and save data in buffer. And then,
output a binary file, which is same format as the inputted file.

Sub ProcessBinaryFile()
Dim inFh As Integer, outFh As Integer
Dim buffer As String

inFh = FreeFile
Open "c:\template5.h5t" For Binary As #inFh
buffer = Space(LOF(inFh))
Get #inFh, , buffer
Close #inFh

outFh = FreeFile
Open "c:\outputtemplate.h5t" For Binary As #outFh
Put #outFh, , buffer
Close #outFh
End Sub

Please give me some suggestion.

Cheers Bon
 
R

Rodrigo Ferreira

Something simple, but not so good...
Put all the file (replacing the strings you want) in other file, remove the
old file and rename the new file to the old name...

Rodrigo Ferreira
 
G

Gary''s Student

Buffer = Replace(Buffer, "student", "teacher")

If your version of Excel does not support Replace, then use
Application.Substitute
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top