+ Reply to Thread
Results 1 to 13 of 13

VBA to Remove Images in Email Body?

  1. #1
    Forum Contributor NewYears1978's Avatar
    Join Date
    03-15-2010
    Location
    Forney, TX
    MS-Off Ver
    Excel 2016
    Posts
    962

    VBA to Remove Images in Email Body?

    Not sure if this is something that can be answered here, I normally get help with Excel stuff

    So something broke with our Outlook at work. We get some generated order confirmation emails that have images in the body, which no longer show up when using excel and if you try to edit the email or forward, it will crash. It's been broke for a month now, IT hasn't been able to fix it.

    I need this workaround so that I can edit these emails, a VBA macro that will simply remove images in the body (without converting it to text, I need it to remain HTML to keep the other formatting)

    Thanks in advance if possible.

  2. #2
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    Office 365 ProPlus
    Posts
    5,882

    Re: VBA to Remove Images in Email Body?

    I'm not quite sure of your situation.

    Here's one way to export .HTMLBODY of an email to text file. Where you can edit it as you see fit.
    You will need to add reference to MS Outlook Object library.
    Please Login or Register  to view this content.
    ?Progress isn't made by early risers. It's made by lazy men trying to find easier ways to do something.?
    ― Robert A. Heinlein

  3. #3
    Forum Contributor NewYears1978's Avatar
    Join Date
    03-15-2010
    Location
    Forney, TX
    MS-Off Ver
    Excel 2016
    Posts
    962

    Re: VBA to Remove Images in Email Body?

    I should have specified it more clearly I think. I need to keep the emails in my inbox. These are order confirmations and I typically just edit the email in Outlook adding notes to the top to keep track. Right now due to the error/crashing I have to manually delete all the images in the email before I can save the edits I have made.

  4. #4
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    Office 365 ProPlus
    Posts
    5,882

    Re: VBA to Remove Images in Email Body?

    Hmm, let me think on this one.

    There is no simple method other than setting .BodyFormat to olFormatPlain to remove images that I'm aware of.

    I'd imagine you'll need to find <img ...> tag and remove them from .HTMLBody or at least edit src property.

  5. #5
    Forum Contributor NewYears1978's Avatar
    Join Date
    03-15-2010
    Location
    Forney, TX
    MS-Off Ver
    Excel 2016
    Posts
    962

    Re: VBA to Remove Images in Email Body?

    Yeah that was my thoughts..the changing to Plain format didn't work as it makes a mess of the information

  6. #6
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    Office 365 ProPlus
    Posts
    5,882

    Re: VBA to Remove Images in Email Body?

    Try this. Uses Regular Expression to find img tags and replace with null string.

    Please Login or Register  to view this content.

  7. #7
    Forum Contributor NewYears1978's Avatar
    Join Date
    03-15-2010
    Location
    Forney, TX
    MS-Off Ver
    Excel 2016
    Posts
    962

    Re: VBA to Remove Images in Email Body?

    Yes it worked!!! Thanks!

  8. #8
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    Office 365 ProPlus
    Posts
    5,882

    Re: VBA to Remove Images in Email Body?

    You are welcome and thanks for the rep

    If this solved your query, please mark the thread as solved by using thread tool found at top of your initial post.

  9. #9
    Forum Contributor NewYears1978's Avatar
    Join Date
    03-15-2010
    Location
    Forney, TX
    MS-Off Ver
    Excel 2016
    Posts
    962

    Re: VBA to Remove Images in Email Body?

    So this has been working great, but we'd like to expand on it. I don't even know if it is possible but here goes.

    Sometimes, there are images embedded down in a reply chain, when we hit reply, outlook is crashing. The macro works to solve this but only if you KNOW there are images and can hit the macro before. I am wondering if there is some Macro that can be run automatically in some way to detect certain text or something?

    Usually the emails with the issues with either say "Order Confirmation" or "Sales Proposal" so my thought was maybe if there is a way to run a macro automatically when you hit Reply (to reply to email, be it shortcut or button) so it does a search in the email for either of those phrases (or maybe something else) and then pop-up will say, warning there are images in this email ro something like that. Then the user can back out and remove the images before replying.

    Our IT department cannot seem to fix this issue and we need some kind of solution as it is constantly crashing outlook.

    Assuming it's something with the "MailItem.Reply Event" or maybe a sub using "ByVal Response" but this is all way over my head. Have been googling will continue to look around


    I tried using this in the ThisOutlookSession but it didn't seem to work (Just as a test using my original macro to see if it would run when I pressed reply..but it did not)

    Please Login or Register  to view this content.
    Last edited by NewYears1978; 03-15-2018 at 10:02 AM.

  10. #10
    Forum Contributor NewYears1978's Avatar
    Join Date
    03-15-2010
    Location
    Forney, TX
    MS-Off Ver
    Excel 2016
    Posts
    962

    Re: VBA to Remove Images in Email Body?

    I tried a bunch of stuff, I could get some Reply button things to work (like placing a subject) but it wouldn't run a macro and I could not find another way to check for text or anything..struggling on this one.

    Apparently this is a known issue from Microsoft for the last 10+ years. They fix it sometimes then break it with another update. It's super frustrating!

  11. #11
    Registered User
    Join Date
    04-14-2018
    Location
    FL, Miami
    MS-Off Ver
    2016
    Posts
    11

    Re: VBA to Remove Images in Email Body?

    I had to do it like this, but I couldn't, thanks for helpful guides

  12. #12
    Registered User
    Join Date
    04-17-2024
    Location
    London, England
    MS-Off Ver
    365
    Posts
    1

    Re: VBA to Remove Images in Email Body?

    I stumbled upon this solution and it still works great. However, I noticed that after I run the macro, even though the inline images get removed, the size of the email remains the same after I close the email and click on "Save" upon being prompted that it has changed.

    I am trying to understand why the size of the email is not reducing even through the images are getting removed.

    Regards

  13. #13
    Registered User
    Join Date
    04-17-2024
    Location
    USA
    MS-Off Ver
    Microsoft 365
    Posts
    5

    Re: VBA to Remove Images in Email Body?

    Quote Originally Posted by denallpan View Post
    I stumbled upon this solution and it still works great. However, I noticed that after I run the macro, even though the inline images get removed, the size of the email remains the same after I close the email and click on "Save" upon being prompted that it has changed.

    I am trying to understand why the size of the email is not reducing even through the images are getting removed.

    Regards
    Great !!!!!!

+ 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. [SOLVED] How can I forward an email, remove FW/RE, delete body and insert signature
    By taylorsm in forum Outlook Formatting & Functions
    Replies: 17
    Last Post: 05-08-2017, 08:23 PM
  2. How to send email from excel using VBA with Cell Range (Including Images) as Email Body
    By Novice_To_Excel in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-24-2014, 05:06 AM
  3. vba pull data from outlook body of email through email or subject of mail into excel
    By breadwinner in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-01-2014, 04:37 AM
  4. Images being removed when transfering email body to new email
    By jstevens124 in forum Outlook Programming / VBA / Macros
    Replies: 0
    Last Post: 08-21-2013, 09:12 PM
  5. Send New Email W/ Body of Received Email, Then Delete Sent Email
    By edneal2 in forum Outlook Formatting & Functions
    Replies: 2
    Last Post: 07-01-2013, 12:45 AM
  6. Replies: 2
    Last Post: 08-01-2012, 02:47 PM
  7. Problem sending images in email body
    By sharky12345 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-21-2012, 07:25 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