LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Save OL Attachments Programatically

I was browsing through the MS Discussion forums and found an entry regarding
saving attachments from outlook via ACCESS vb code (code snippet from Joe
Fallon below). I have a similar issue where I receive an email daily that
contains an excel spreadsheet. I then have to save that attachement to any
random location, import it into my db, store the raw data, manipulate it,
run several comparisons against it, and then spit it back out into a
formatted spreadsheet that gets distributed to one of several users as a
daily work file.

This all works fine with the current coding that I've written. What I'm not
paricularly thrilled about, though, is having to manualy save that file from
the email attachment before running the code.
I used the code you provided the other user by Joe Fallon (and modified
particular areas to fit my needs) but I'm getting stuck.
I keep getting a break on the line:
Set MyInbox = ns.GetDefaultFolder(olFolderInbox).Items
with the error:
Method 'Items' of object 'MAPIfolder' failed

I've checked Tools,-References and I have an Outlook group checked, but I'm
lost for any other solutions.

If you have any suggestions, they would be greatly appreciated. My bosses
are breathing down my neck about this (they're rather picky and don't want
end-users to do much prep on their own).

Thanks.

The code listed in the forums was:
Public Sub SaveAttachment(strPath As String)
On Error GoTo Err_SaveAttachment

Dim ol As New Outlook.Application
Dim ns As Outlook.NameSpace
Dim MyInbox As Outlook.Items
Dim fldr As Outlook.MAPIFolder
Dim itm As Outlook.MailItem
Dim mFile As String, NumAttachments As Integer, i As Integer, NumEmails As
Integer, strTo As String

Set ns = ol.GetNamespace("MAPI")
Set MyInbox = ns.GetDefaultFolder(olFolderInbox).Items

'set a reference to a folder to move the items to
Set fldr = ns.Folders("Personal Folders").Folders("Saved
Messages").Folders("Bids")

For Each itm In MyInbox
'Debug.Print itm.Subject, itm.To, itm.SenderName
! If itm.Subject Like "*Bid*" Then
NumAttachments = itm.Attachments.Count
i = 1 'attachment number
Do While i <= NumAttachments
mFile = itm.Attachments.Item(i).filename
itm.Attachments.Item(i).SaveAsFile strPath & mFile
i = i + 1
Loop
Else
'Debug.Print "Not a Bid"
End If
Next

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
attachments - KIRK Setting up and Configuration of Excel 0 September 28th 07 08:01 PM
attachments Paul Excel Discussion (Misc queries) 3 September 5th 07 12:34 PM
Attachments meyer99 Excel Worksheet Functions 1 June 22nd 05 10:11 AM
Attachments Gerry[_8_] Excel Programming 2 February 11th 05 06:26 PM
save file as addin programatically Bura Tino Excel Programming 1 May 10th 04 06:07 PM


All times are GMT +1. The time now is 12:19 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"