+ 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
    71

    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
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,532

    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>".
    Jeff
    | | |·| |·| |·| |·| | |:| | |·| |·|
    Read the rules
    Use code tags to [code]enclose your code![/code]

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

    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
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,532

    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
    71

    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
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,532

    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
    71

    Re: Replace text in HTMLBody

    HTML Code: 
    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
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,532

    Re: Replace text in HTMLBody

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

  9. #9
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,532

    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
    71

    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
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,532

    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)

Similar Threads

  1. Cdo smtp - combine textbody with htmlbody
    By pulsar777 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-14-2018, 05:01 PM
  2. Help with HTMLBody formatting
    By starlev in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 05-20-2015, 10:00 AM
  3. How to insert signature in email using .HTMLbody
    By sugaprasad in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-01-2015, 06:28 AM
  4. Textbox (enter key) not giving a new line in HTMLBody
    By milo1984 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-09-2013, 09:18 AM
  5. Cell value in HTMLBody
    By mcinnes01 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-14-2011, 08:03 AM
  6. Email specific range of cells using .htmlbody
    By Jason Smith in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-19-2008, 03:01 PM
  7. outlook htmlbody
    By Erin in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-06-2005, 03:06 AM

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