+ Reply to Thread
Results 1 to 11 of 11

Replace text in HTMLBody

  1. #1
    Registered User
    Join Date
    11-09-2016
    Location
    London, England
    MS-Off Ver
    2010/2016
    Posts
    36

    Replace text in HTMLBody

    Hi

    I have created a message template and am calling that template replacing 'fields' in the subject and (html) body based on values from a form. This works well.

    I one case, I need to remove a entire paragraph if an option is not used on the form. The paragraph is made up of both normal weight and bold weight text.

    Please Login or Register  to view this content.
    The [dog] part is bold ('strong' style). If I try to replace "The quick brown fox jumps over the lazy [dog]." with nothing, it doesn't work. I assume because of the bold weight having formatting/html tags around it?)

    Is there a right way to handle these situations without including the html tags in the replace?

    Thanks

  2. #2
    Forum Moderator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    Pro 2019
    Posts
    14,664

    Re: Replace text in HTMLBody

    If you are manipulating existing HTMLBody then you have to take the HTML tags into consideration. You cannot just look for "lazy [dog]" you have to look for "lazy <strong>[dog]</strong>".
    Making the world a better place one fret at a time | | |會 |會 |會 |會 | |:| | |會 |會
    Please read the rules
    If someone helped you, click on the star icon at the bottom of their post
    If your problem is solved, go to Thread Tools and select Mark This Thread Solved
    Don't attach a screenshot--just attach your Excel file! It's easier and will let us experiment with your data, formulas, and code.

  3. #3
    Registered User
    Join Date
    11-09-2016
    Location
    London, England
    MS-Off Ver
    2010/2016
    Posts
    36

    Re: Replace text in HTMLBody

    Thanks.

    That didn't work as style tags are added to the strong tags so it would have been required to add them all!

    I changed to bookmarks and it's much cleaner now, though that's introduced another niggle!

  4. #4
    Forum Moderator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    Pro 2019
    Posts
    14,664

    Re: Replace text in HTMLBody

    I can provide more specific help if you can provide an actual sample of the HTML you are trying to parse.

  5. #5
    Registered User
    Join Date
    11-09-2016
    Location
    London, England
    MS-Off Ver
    2010/2016
    Posts
    36

    Re: Replace text in HTMLBody

    Dear [addressee],

    Re: [title]
    ......[owner]


    [description]

    [The due date for response is [due].]

    Kind regards,


    Both the [description] bookmark and due line are conditional, but not of each other.

  6. #6
    Forum Moderator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    Pro 2019
    Posts
    14,664

    Re: Replace text in HTMLBody

    That is not HTML, it is plain text.

  7. #7
    Registered User
    Join Date
    11-09-2016
    Location
    London, England
    MS-Off Ver
    2010/2016
    Posts
    36

    Re: Replace text in HTMLBody

    HTML Code: 
    [body lang=EN-GB link="#0563C1" vlink="#954F72"]
    	[div class=WordSection1]
    		[p class=MsoNormal]Dear Sirs,[o:p][/o:p][/p]
    		[p class=MsoNormal][o:p]&nbsp;[/o:p][/p]
    		[p class=MsoNormal][strong][span style='font-family:"Arial",sans-serif']Re:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; This is the title[o:p][/o:p][/span][/strong][/p]
    		[p class=MsoNormal][strong][span style='font-family:"Arial",sans-serif']&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; This is the owner[o:p][/o:p][/span][/strong][/p]
    		[p class=MsoNormal][o:p]&nbsp;[/o:p][/p]
    		[p class=MsoNormal]This is the description.[o:p][/o:p][/p]
    		[p class=MsoNormal][o:p]&nbsp;[/o:p][/p]
    		[p class=MsoNormal][a name=duetext]The due date for response is [strong][span style='font-family:"Arial",sans-serif']1 December 2018[/span][/strong][/a][span style='mso-bookmark:duetext'].[/span][o:p][/o:p][/p]
    		[p class=MsoNormal][o:p]&nbsp;[/o:p][/p]
    		[p class=MsoNormal]Kind regards,[o:p][/o:p][/p]
    		[p class=MsoNormal][o:p]&nbsp;[/o:p][/p]
    		[p class=MsoNormal][o:p]&nbsp;[/o:p][/p]
    	[/div]
    [/body]
    Had to swap to [] as it wouldn't let me use HTML code (no matter if I wrap in code or html tags)

  8. #8
    Forum Moderator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    Pro 2019
    Posts
    14,664

    Re: Replace text in HTMLBody

    Oh, yeah. They have a filter that is overly aggressive about injection attacks. I'll look shortly.

  9. #9
    Forum Moderator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    Pro 2019
    Posts
    14,664

    Re: Replace text in HTMLBody

    I can provide a solution that uses regex but I am still not sure how to identify the part you want to replace. Your first post says "I need to remove a entire paragraph if an option is not used on the form" but I can't tell from your HTML what option or what paragraph that might be and how to tell whether the option is used.

  10. #10
    Registered User
    Join Date
    11-09-2016
    Location
    London, England
    MS-Off Ver
    2010/2016
    Posts
    36

    Re: Replace text in HTMLBody

    Thanks for your help. I know regex so if that is your suggestion then I'm ok.

    I just wondered if there was any way to do a replace that ignores html formatting. Maybe regex would be cleaner than bookmarks:

    Please Login or Register  to view this content.

  11. #11
    Forum Moderator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    Pro 2019
    Posts
    14,664

    Re: Replace text in HTMLBody

    If you have set up the bookmarks, and the code works, then it seems like you're done--what's the new niggle?

    You are doing two things I have no experience with: Using an Outlook template, and using Word in VBA to edit an Outlook item. So not sure if can help further.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1