JoeMajestee
New Member
- Joined
- Jul 15, 2009
- Messages
- 49
Hi all.
I am working on an Excel 2003 macro that emails from Outlook using a template. The template is, of course, HTML. I wish to replace some text in the template with other text. I am using worksheetfunction.replace with some success, but think there might be a non worksheet function ie. VBA function that does it better or the same.
The pertinent code snippet is:
The macro works almost. Every now and then it won't do the replace in one of several replacements and it is consistently the same replacement. At first I realized it is because the HTML got borked up so the text being manipulated might appear to read "watermelon" but looking at the HTML result was "wa><span something>termelon". I have since made sure the text being replaced actually existed as text in the htmlbody, so that is not causing my problem. I have carefully copied and pasted, etc, to be sure there was not an errant space or something in the text either.
Thanks.
I am working on an Excel 2003 macro that emails from Outlook using a template. The template is, of course, HTML. I wish to replace some text in the template with other text. I am using worksheetfunction.replace with some success, but think there might be a non worksheet function ie. VBA function that does it better or the same.
The pertinent code snippet is:
Code:
For Each c1 In Range(Cells(1, 1), Cells(1, Cells(1, 200).End(xlToLeft).Column))
strHTMLbody = Application.WorksheetFunction.Replace _
(strHTMLbody, InStr(1, strHTMLbody, c1.Value, vbTextCompare), _
Len(c1.Value), Cells(c.Row, c1.Column).Value)
OutMail.htmlbody = strHTMLbody
Next c1
The macro works almost. Every now and then it won't do the replace in one of several replacements and it is consistently the same replacement. At first I realized it is because the HTML got borked up so the text being manipulated might appear to read "watermelon" but looking at the HTML result was "wa><span something>termelon". I have since made sure the text being replaced actually existed as text in the htmlbody, so that is not causing my problem. I have carefully copied and pasted, etc, to be sure there was not an errant space or something in the text either.
Thanks.