This should get you close. I added an extra function should you want to just replace the first string. I coded it to replace the whole element in the array if the string tag was found.
Don't forget to replace the lines with BCard_files and bcard.htm to suit your paths and filenames.
Sub Mail_Outlook_With_Signature_Html_3()
' Don't forget to copy the function GetBoiler in the module.
' Working in Office 2000-2013
Dim OutApp As Object
Dim OutMail As Object
Dim strbody As String
Dim SigString As String
Dim Signature As String
Dim img As String, s() As String, i As Long
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
strbody = "<H3><B>Dear Customer Ron de Bruin</B></H3>" & _
"Please visit this website to download the new version.<br>" & _
"Let me know if you have problems.<br>" & _
"<A HREF=""http://www.rondebruin.nl/tips.htm"">Ron's Excel Page</A>" & _
"<br><br><B>Thank you</B>"
'Change only Mysig.htm to the name of your signature
SigString = Environ("appdata") & _
"\Microsoft\Signatures\bcard.htm"
If Dir(SigString) <> "" Then
Signature = GetBoiler(SigString)
img = " <v:imagedata src=" & _
Environ("appdata") & "\Microsoft\Signatures\BCard_files\image001.jpg" & _
" o:title=""""/>"
s() = Split(Signature, vbCrLf)
MsgBox UBound(s)
i = IndexInArray("<v:imagedata src=", s()) '-1 = not found. 3rd Parameter is False by default.
'i = IndexInArray("src=", s(), True) '-1 = not found. True means matched to left side of string.
If i <> -1 Then
'Show full array element value in Immediate Window
'for a found string in the first element matched.
'Debug.Print s(i)
s(i) = img
Signature = Join(s, vbCrLf)
End If
Exit Sub
Else
Signature = ""
End If
On Error Resume Next
With OutMail
.to = "kenneth.ray.hobson@gmail.com"
.CC = ""
.BCC = ""
.Subject = "This is the Subject line"
.HTMLBody = strbody & "<br>" & Signature
.Send 'or use .Display
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
End Sub
'If not found, result is -1. Set cm=vbBinaryCompare for exact string comparison.
Function IndexInArray(aValue As String, anArray() As String, _
Optional tfMatchLeft As Boolean = False, Optional cm As Integer = vbTextCompare) As Long
Dim pos As Long, i As Long, ii As Integer
pos = -1
For i = LBound(anArray) To UBound(anArray)
ii = InStr(1, anArray(i), aValue, cm)
If ii <> 0 Then
If tfMatchLeft = True Then
If ii = 1 Then pos = i
Exit For
Else
pos = i
Exit For
End If
End If
Next i
IndexInArray = pos
End Function
Sub Test_ReplaceFirstString()
Dim s As String
s = " <v:imagedata src=""C:\Users\vanhunkh\AppData\Roaming\Microsoft\Signatures\MyCompany_files\image001.jpg"" o:title=""""/>"
Debug.Print ReplaceFirstString(s, "ken")
End Sub
Function ReplaceFirstString(aString As String, replaceString As String) As String
Dim s() As String
s() = Split(aString, """")
If UBound(s) >= 1 Then s(1) = replaceString
ReplaceFirstString = Join(s, """")
End Function
Function GetBoiler(ByVal sFile As String) As String
'Dick Kusleika
Dim fso As Object
Dim ts As Object
Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.GetFile(sFile).OpenAsTextStream(1, -2)
GetBoiler = ts.readall
ts.Close
End Function