Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Open an attachment in a new window using its native application

369 views
Skip to first unread message

Tony29

unread,
May 24, 2008, 6:49:00 AM5/24/08
to
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

JP

unread,
May 25, 2008, 9:21:27 AM5/25/08
to
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

Sue Mosher [MVP-Outlook]

unread,
May 25, 2008, 9:51:10 AM5/25/08
to
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.
--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54


"Tony29" <To...@bigpond.com.au> wrote in message news:128BB813-BBC8-41F2...@microsoft.com...

0 new messages