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!
-----------
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!