Saving Images in Outlook 2007

Programmatically, of course.

Having already asked this question on the superuser, I'm looking to write a simple macro to pull out the displayed image in an HTML message (email or feed) in Outlook 2007, and let me save it to disk.

Unfortunately, I could not find where in the OL object model I can refer either to related images or to the html content itself. Finding attachments is easy, these are related / displayed images that are my problem.

Any help? Of course, if you have the best non-programmatic answer, I will be glad to see that - over the superuser, of course ...

+6
outlook outlook-2007
source share
2 answers

It is based on MSDN docs. I do not have Outlook to test.

Assuming you have an email open, you can call the GetInspector method on the GetInspector instance that you have and use its HTMLEditor property to access the DOM.

Here you can call ordinary methods, such as document.Images , to access all elements of the image. I donโ€™t know how to save it locally to disk, but Iโ€™m sure there must be some method for this.

+2
source share

I had a second look at shahkalpeshs answer and came up with the following solution: (Written in Outlook 2003)

 Option Explicit Private Sub getImages() Dim xmlhttp_ As xmlhttp Dim htmldoc As Object Dim currentImage As Object Dim currentResponse() As Byte Dim startTime As Date Dim maxTime As Long Dim pathFolder As String Dim pathFull As String Dim nrFile As Integer pathFolder = "C:\YourFolder\Images\" '"(small fix for stackoverflow syntaxhighlighter) maxTime = 30 ' max time to load 1 File in seconds ' If Me.ActiveWindow.CurrentItem.GetInspector.EditorType = olEditorHTML Then Set htmldoc = Me.ActiveWindow.CurrentItem.GetInspector.HTMLEditor Set xmlhttp_ = New xmlhttp For Each currentImage In htmldoc.images xmlhttp_.Open "GET", currentImage.src If Left(currentImage.src, 8) <> "BLOCKED:" Then xmlhttp_.Send startTime = Now pathFull = pathFolder & currentImage.nameProp pathFull = Replace(pathFull, "?", vbNullString) pathFull = Replace(pathFull, "&", vbNullString) Do While xmlhttp_.readyState <> 4 If DateTime.DateDiff("s", startTime, Now) > maxTime Then Exit Do DoEvents Loop If xmlhttp_.readyState = 4 Then If Dir(pathFull) <> "" Then Kill pathFull nrFile = freeFile Open pathFull For Binary As #nrFile currentResponse = xmlhttp_.responseBody Put #nrFile, , currentResponse Close #nrFile End If End If Next currentImage End If Set xmlhttp_ = Nothing Set currentImage = Nothing Set htmldoc = Nothing End Sub 

This code will download all images in ActiveWindow and save them in a folder.

You will need to add a link to Microsoft XML (any version> = 2.6 should work) using the tools-> Links in the VBA editor

If you want, you can also set the link to the Microsoft HTML Object Library and change:

  Dim htmldoc As Object Dim currentImage As Object 

in

  Dim htmldoc As HTMLDocument Dim currentImage As HTMLImg 

Regarding your comment:

@marg, Thanks for the detailed answer. I still cannot believe that the solution should be so confusing - the image is already displayed, why should I download it again? But what if I want to save only one image? (In Outlook 2003, you were able to right-click on the image and choose to save as ... now no more.) Since this is a close for a real workable solution, and since there is no better solution in current Outlook - I give you generosity ...

I do not have 2007 to search for a non-programming solution.

I donโ€™t think the MailItem Object ( CurrentItem in my solution is MailItem ) is very different between versions (but I base this assumption on 0% research: D) and I couldnโ€™t find the direct local path where the displayed images are stored, although I sure that they should be in the browser cache folder. An alternative solution would be to bypass your folder for the file named currentImage.nameProp and copy it to the destination folder. Just reloading the image should not be so bad: D

+1
source share

All Articles