Open an attachment in a new window using its native application

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
 
J

JP

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
 
S

Sue Mosher [MVP-Outlook]

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.
 

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