Showing attached pictures

K

Kevin

I'm using MS Outlook 2003, and all pictures come in as
attachments. I would like to view the pictures in the body
of the email. Help!
 
P

P_Lee

Try this macro I put together for a work-around....

Select one or multiple emails (you do not
have to open them first). Picture attachments will show up in a new browser
window, other attachments will just show as a red 'X' .

- It's safe, because it won't run any executables or other attachments.
- Put a shortcut to the macro on your toolbar for easy access.
- You can select multiple emails & display all the attachments at once.
- It copies the files to 'c:\attachments_outlook' (creates the directory
if necessary - you can modify the path if you wish).
- It then deletes the specific files that were copied (no others).



Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Sub view_attachments()
On Error Resume Next

Dim oOL As Outlook.Application
Dim oSelection As Outlook.Selection

Set oOL = New Outlook.Application
Set oSelection = oOL.ActiveExplorer.Selection
Set fs = CreateObject("Scripting.FileSystemObject")

vPath = "c:\Attachments_Outlook\"
If Not fs.FolderExists(vPath) Then fs.CreateFolder vPath

vHTMLBody = "<HTML><title>View Email Attachments</title>"

For Each obj In oSelection
vSubject = "<FONT face=Arial size=3>Attachments from: <b>" _
& obj.Subject & "</b><br>"
vHTMLBody = vHTMLBody & vSubject
For Each Attachment In obj.Attachments
Attachment.SaveAsFile (vPath & Attachment.FileName)
vHTMLBody = vHTMLBody & Attachment.FileName & "</Font><br>" _
& "<IMG alt="""" hspace=0 src=""" & vPath & Attachment.FileName _
& """ align=baseline border=0><br><br><br>"
Next
Next
vHTMLBody = vHTMLBody & "</html>"

Set ie = CreateObject("internetexplorer.application")
With ie
.toolbar = 0
.menubar = 0
.statusbar = 0
.Left = 100
.Top = 100
.Height = 480
.Width = 640
.navigate "about:blank"
.document.Open
.document.Write vHTMLBody
.document.Close
.Visible = True
End With

Do Until ie.readyState = 4: Sleep 10: Loop
Set ie = Nothing

For Each obj In oSelection
For Each Attachment In obj.Attachments
fs.DeleteFile (vPath & Attachment.FileName)
Next
Next

Set fs = Nothing
Set objMsg = Nothing
Set oSelection = Nothing
Set oOL = Nothing
End Sub
 
J

Jocelyn Fiorello [MVP - Outlook]

Outlook can only display images "inline" if the sender used HTML or Rich
Text format for the message and embedded the image into the body. If the
image was sent as an attachment, you will always receive it as an
attachment.

--
Jocelyn Fiorello
MVP - Outlook

*** Messages sent to my e-mail address will NOT be answered -- please
reply only to the newsgroup to preserve the message thread. ***


In
 
G

Guest

I used the macro that you developed in outlook and really like it but there is one question I have

My Cousin sent me a picture from her digital camera without making it small it is like 2000x1500 pixels. So when I view the pic with your macro I can’t see it all without scrolling. Also for some reason it doesn’t give the option in the lower right hand side of fitting the pic to the window. Do you know of a way to make it so I can

Thanks

Emil
 
P

P_Lee

I've run into that problem too.

You won't get the button in the lower right-hand corner, because according to
Microsoft "Automatic Image Resizing works only when users navigate directly to
pictures. Internet Explorer cannot resize pictures that are embedded within
HTML pages."

Anyway, here's a modified version of the macro that uses javascript to scale
images larger than the width of the browser (currently hard-coded to 800).

Try it out & let me know what you think. (Don't copy the 'Public Declare...'
line again if you already have it).



Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Sub view_attachments()
On Error Resume Next

Dim oOL As Outlook.Application
Dim oSelection As Outlook.Selection

Set oOL = New Outlook.Application
Set oSelection = oOL.ActiveExplorer.Selection
Set fs = CreateObject("Scripting.FileSystemObject")

vPath = "c:\Attachments_Outlook\"
If Not fs.FolderExists(vPath) Then fs.CreateFolder vPath

vHTMLBody = "<HTML><title>View Email Attachments</title>"

For Each obj In oSelection
vSubject = "<FONT face=Arial size=3>Attachments from: <b>" _
& obj.Subject & "</b><br>"
vHTMLBody = vHTMLBody & vSubject
For Each Attachment In obj.Attachments
Attachment.SaveAsFile (vPath & Attachment.FileName)
vHTMLBody = vHTMLBody & Attachment.FileName & "</Font><br>" _
& "<IMG alt="""" hspace=0 src=""" _
& vPath & Attachment.FileName _
& """ align=baseline border=0><br><br><br>"
Next
Next

vHTMLBody = vHTMLBody & "<SCRIPT LANGUAGE=""JavaScript"">" _
& "vWidth=document.body.clientWidth;" _
& "for (var i=0; i<document.images.length; i++)" _
& "if (document.images.width > vWidth) {" _
& "document.images.width = vWidth;}" _
& "</SCRIPT>"

vHTMLBody = vHTMLBody & "</html>"

Set ie = CreateObject("internetexplorer.application")
With ie
.toolbar = 0
.menubar = 0
.statusbar = 0
.Left = 100
.Top = 50
.Height = 600
.Width = 800
.navigate "about:blank"
.document.Open
.document.Write vHTMLBody
.document.Close
.Visible = True
End With

Do Until ie.readyState = 4: Sleep 10: Loop
Set ie = Nothing

For Each obj In oSelection
For Each Attachment In obj.Attachments
fs.DeleteFile (vPath & Attachment.FileName)
Next
Next

Set fs = Nothing
Set objMsg = Nothing
Set oSelection = Nothing
Set oOL = Nothing
End Sub
 
P

P_Lee

Updated version of the view attachments macro.

- Saves files in temporary internet folders instead of creating directory.
Files are automatically deleted from temporary folders when Outlook is closed.
- Allows right-click of image to 'Save As', 'Email', 'Print' etc. (previous
version deleted files, so this functionality did not work).
- Fixed auto resizing of images to browser width (previous version sometimes
didn't resize extremely large images the first time). If you want to resize
manually just resize the browser window, right-click, & choose 'Refresh' to
scale the images to the new browser width.

Please try it out & give me some feedback....



Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Sub view_attachments()
'********************************************************************
' ver. 1/21/04 - Copies files to Temporary Internet folders.
' This enables right-click access to 'Save As', 'Email', etc.
' Files are automatically deleted when Outlook is closed.
'********************************************************************
On Error Resume Next

Dim oOL As Outlook.Application
Dim oSelection As Outlook.Selection

Set oOL = New Outlook.Application
Set oSelection = oOL.ActiveExplorer.Selection
Set objShell = CreateObject("WScript.Shell")

vTempInt = objShell.RegRead("HKCU\software\microsoft\" _
& "Windows\CurrentVersion\Explorer\Shell Folders\Cache")
vPath = vTempInt & "\"

vHTMLBody = "<HTML><title>View Email Attachments</title>"
vEmailNum = 0
For Each obj In oSelection
vEmailNum = vEmailNum + 10
vSubject = "<FONT face=Arial size=3>Attachments from: <b>" _
& obj.Subject & "</b><br>"
vHTMLBody = vHTMLBody & vSubject
vAttachNum = vEmailNum
For Each Attachment In obj.Attachments
vAttachNum = vAttachNum + 1
vImg = "document.img" & vAttachNum
Attachment.SaveAsFile (vPath & Attachment.FileName)
vHTMLBody = vHTMLBody & Attachment.FileName & "</Font><br>" _
& "<IMG name=""img" & vAttachNum & """" & " alt=""""" _
& " hspace=0 src=""" & vPath & Attachment.FileName _
& """ align=baseline border=0 " & "onload=""" _
& "vWidth=document.body.clientWidth;" _
& "if (" & vImg & ".width > vWidth) {" _
& vImg & ".width = vWidth;}""" _
& "><br><br><br>"
Next
Next

vHTMLBody = vHTMLBody & "</html>"

Set ie = CreateObject("internetexplorer.application")
With ie
.toolbar = 0
.menubar = 0
.statusbar = 0
.Left = 100
.Top = 50
.Height = 600
.Width = 800
.navigate "about:blank"
.document.Open
.document.Write vHTMLBody
.document.Close
.Visible = True
End With

Do Until ie.readyState = 4: Sleep 10: Loop
Set ie = Nothing

Set objShell = Nothing
Set objMsg = Nothing
Set oSelection = Nothing
Set oOL = Nothing
End Sub
 
G

Guest

Hi Patrick,

Just wanted to give you feedback on this macro and thank you. I didn't even know what a "macro" did when I read your posts today, but I did my homework and was able to get it up and running in Outlook and it is WONDERDFUL! I even made a toolbar button for it, like you suggested. My photo editor program took FOREVER to load up the pics when I opened them, and it was driving me CRAZY. You saved my sanity! Thanks so much!

Kristina

----- P_Lee wrote: -----

Updated version of the view attachments macro.

- Saves files in temporary internet folders instead of creating directory.
Files are automatically deleted from temporary folders when Outlook is closed.
- Allows right-click of image to 'Save As', 'Email', 'Print' etc. (previous
version deleted files, so this functionality did not work).
- Fixed auto resizing of images to browser width (previous version sometimes
didn't resize extremely large images the first time). If you want to resize
manually just resize the browser window, right-click, & choose 'Refresh' to
scale the images to the new browser width.

Please try it out & give me some feedback....



Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Sub view_attachments()
'********************************************************************
' ver. 1/21/04 - Copies files to Temporary Internet folders.
' This enables right-click access to 'Save As', 'Email', etc.
' Files are automatically deleted when Outlook is closed.
'********************************************************************
On Error Resume Next

Dim oOL As Outlook.Application
Dim oSelection As Outlook.Selection

Set oOL = New Outlook.Application
Set oSelection = oOL.ActiveExplorer.Selection
Set objShell = CreateObject("WScript.Shell")

vTempInt = objShell.RegRead("HKCU\software\microsoft\" _
& "Windows\CurrentVersion\Explorer\Shell Folders\Cache")
vPath = vTempInt & "\"

vHTMLBody = "<HTML><title>View Email Attachments</title>"
vEmailNum = 0
For Each obj In oSelection
vEmailNum = vEmailNum + 10
vSubject = "<FONT face=Arial size=3>Attachments from: <b>" _
& obj.Subject & "</b><br>"
vHTMLBody = vHTMLBody & vSubject
vAttachNum = vEmailNum
For Each Attachment In obj.Attachments
vAttachNum = vAttachNum + 1
vImg = "document.img" & vAttachNum
Attachment.SaveAsFile (vPath & Attachment.FileName)
vHTMLBody = vHTMLBody & Attachment.FileName & "</Font><br>" _
& "<IMG name=""img" & vAttachNum & """" & " alt=""""" _
& " hspace=0 src=""" & vPath & Attachment.FileName _
& """ align=baseline border=0 " & "onload=""" _
& "vWidth=document.body.clientWidth;" _
& "if (" & vImg & ".width > vWidth) {" _
& vImg & ".width = vWidth;}""" _
& "><br><br><br>"
Next
Next

vHTMLBody = vHTMLBody & "</html>"

Set ie = CreateObject("internetexplorer.application")
With ie
.toolbar = 0
.menubar = 0
.statusbar = 0
.Left = 100
.Top = 50
.Height = 600
.Width = 800
.navigate "about:blank"
.document.Open
.document.Write vHTMLBody
.document.Close
.Visible = True
End With

Do Until ie.readyState = 4: Sleep 10: Loop
Set ie = Nothing

Set objShell = Nothing
Set objMsg = Nothing
Set oSelection = Nothing
Set oOL = Nothing
End Sub
 
G

Guest

P_Lee

Thank you veery much. Works just fine :
Saved a lot of tim

Ozgu
Istanbul, Turkey
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top