#  Other Applications & Softwares  > Outlook Formatting & Functions >  > [SOLVED] VBA to Remove Images in Email Body?

## NewYears1978

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

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.

----------


## CK76

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.
```

----------


## NewYears1978

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.

----------


## CK76

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.

----------


## NewYears1978

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

----------


## CK76

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




```
Please Login or Register  to view this content.
```

----------


## NewYears1978

Yes it worked!!! Thanks!

----------


## CK76

You are welcome and thanks for the rep  :Smilie: 

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

----------


## NewYears1978

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  :Smilie: 


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.
```

----------


## NewYears1978

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!

----------


## KaelWis

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

----------

