Open an attachment in a new window using its native application

  • Thread starter Thread starter Tony29
  • Start date Start date
T

Tony29

I have VBA code that loops through the attachments of an email item. For
each attachment that is clearly a document (eg. .doc, .xls, .pdf, etc) I want
to open that document in a separate window using it's native application.
The effect is just like the user double-clicking on the normal attachment
icon when reading an email in a normal email window.

I'm hoping this is not complicated by needing to know what application is
the native application and creating the relevant object ... etc.

In Access I can use ...
Application.FollowHyperlink stFile, , True
... but there doesn't seem to have be a similar meethod in Outlook

Tony
 
One way is to use a Select Case statement to check the last three
digits of the filename and open the appropriate program. Of course you
would need to save the file first, using the SaveAsFile Method on each
member of the Attachments Collection. Here's some air code:

Select Case Right$(Filename, 3)
Case "doc"
Set WordApp = CreateObject("Word.Application")
WordApp.Open Filename
Case "xls"
Set XLApp = CreateObject("Word.Application")
XLApp.Open Filename
End Select

' delete the file after finished
On Error Resume Next
Kill Filename
On Error Goto 0


HTH,
JP
 
The generic approach is to use Windows Script Host:

Set Myshell = CreateObject("WScript.Shell") 'Windows Scripting Host Object
Myshell.Run "C:\some file name.ext"

You must save the attachment to the local file system first, of course, as JP noted.
 
Back
Top