A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

VBA to Open Attatchments



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old October 17th 06, 06:09 PM posted to microsoft.public.outlook.program_vba
Whelan
external usenet poster
 
Posts: 1
Default 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


  #2  
Old October 17th 06, 07:13 PM posted to microsoft.public.outlook.program_vba
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default 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



  #3  
Old October 17th 06, 07:16 PM posted to microsoft.public.outlook.program_vba
Eric Legault [MVP - Outlook]
external usenet poster
 
Posts: 830
Default 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


 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Open appointments from VBA Form? Sangeeta Outlook - Calandaring 0 June 20th 06 09:21 PM
How to open Public Folders 'Contact Form' using VBA mmattson Outlook and VBA 1 May 17th 06 11:06 PM
VBA Code not running until editor is open gamename Outlook and VBA 0 May 17th 06 06:42 PM
PDF Attatchments Won't Open jimbo 6 Outlook Express 7 March 29th 06 09:09 PM
possible to open two profiles at the same time with VBA??? carteriii Outlook and VBA 2 February 8th 06 05:47 PM


All times are GMT +1. The time now is 08:24 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.