Outlook Banter

Outlook Banter (http://www.outlookbanter.com/)
-   Outlook and VBA (http://www.outlookbanter.com/outlook-vba/)
-   -   VBA to Open Attatchments (http://www.outlookbanter.com/outlook-vba/30257-vba-open-attatchments.html)

Whelan October 17th 06 06:09 PM

VBA to Open Attatchments
 

Hello there,

New to VBA in Outlook, and have a quick question;

There are a number of emails that drop into a joint inbox in my department.
These emails contain excel attachments. I can write some VBA code to deal
with the attachment in excel, but would like to totally automate the process
by writing some VB in Outlook to open up the attachment based on the Email
Subject line??

Would be grateful for a few lines to get me started.

Thanks in advance

Whelan



Ken Slovak - [MVP - Outlook] October 17th 06 07:13 PM

VBA to Open Attatchments
 
In order to do any manipulation of an Attachment object you need to save it
to the file system. You can use the SaveAs method to do that.

Once you have saved an attachment then manipulating it in code depends on
what type of file the attachment is. If it's a Word file for example you'd
automate Word to open it.

Take a look at the code at
http://www.slovaktech.com/code_sampl...ripAttachments for an example
of working with attachments in code.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"Whelan" wrote in message
...

Hello there,

New to VBA in Outlook, and have a quick question;

There are a number of emails that drop into a joint inbox in my
department.
These emails contain excel attachments. I can write some VBA code to deal
with the attachment in excel, but would like to totally automate the
process
by writing some VB in Outlook to open up the attachment based on the Email
Subject line??

Would be grateful for a few lines to get me started.

Thanks in advance

Whelan




Eric Legault [MVP - Outlook] October 17th 06 07:16 PM

VBA to Open Attatchments
 
The short version of how to do this:

- call Attachment.SaveAs
- output to a directory of your choice
- use the ShellExecute Win32API function to run the file as if you
double-clicked it

Here's an example:

'Code for the General Declarations section of your module
Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
(ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String _
, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal
nShowCmd As Long) As Long
Public Const conSwNormal = 1

'Sample calling code
ShellExecute 0, "open", "C:\Temp\Sheet1.xls", vbNullString, "C:\Temp",
conSwNormal

I've written an MSDN article as well that details a similar approach for a
larger solution if you want to see an example in context:

Office Developer Center: Viewing Multiple Picture Attachments in Outlook
2003:
http://msdn.microsoft.com/office/def...PictAttach.asp

--
Eric Legault (Outlook MVP, MCDBA, MCTS: Messaging & Collaboration)
Try Picture Attachments Wizard for Outlook:
http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault/


"Whelan" wrote:


Hello there,

New to VBA in Outlook, and have a quick question;

There are a number of emails that drop into a joint inbox in my department.
These emails contain excel attachments. I can write some VBA code to deal
with the attachment in excel, but would like to totally automate the process
by writing some VB in Outlook to open up the attachment based on the Email
Subject line??

Would be grateful for a few lines to get me started.

Thanks in advance

Whelan




All times are GMT +1. The time now is 10:17 AM.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2006 OutlookBanter.com