Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Find/replace a string in binary file

Status
Not open for further replies.

icelancer

Technical User
Sep 23, 2010
1
US
Hey everyone! I have an issue with find/replace of a string. Here's my code:

-----------
Sub EditHTML()

Dim mit As MailItem
Dim fname As String
Dim fcon As String
Dim stringExists As Boolean

If Application.ActiveInspector.CurrentItem.Class <> olMail Then
MsgBox "The HTML Code cannot be edited for this item." & vbCrLf & "Only Mail Items are supported.", vbExclamation, "Edit HTML Error"
Exit Sub
End If

Set mit = Application.ActiveInspector.CurrentItem
fname = Environ$("temp") & "\htmlmessage.txt"
On Error Resume Next
Kill fname
Open fname For Binary As #1
Put #1, , mit.HTMLBody
If InStr(1, mit.HTMLBody, "<table") Then
StringExistsInFile = True
End If
Close #1

Shell "notepad.exe " & fname, vbMaximizedFocus
MsgBox "Click OK to save your changes to the HTML!", vbOKOnly + vbInformation, "Edit HTML"

Open fname For Binary As #1
fcon = Space(LOF(1))
Get #1, , fcon
Close #1

mit.HTMLBody = fcon
End Sub

-------

What I need this script to do is to go through the file line by line and find all instances of "<table", then deleting that line and replacing it with a static variable.

Right now it calls notepad for this manual process, and I use instr to find the instance of <table, but it's not a loop and I am stuck on how to delete the line and replace it with something static.

Help! Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top