Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / January 2006

Tip: Looking for answers? Try searching our database.

save e mail attachments and remove them

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jaime - 23 Jan 2006 23:16 GMT
I need help:
I need to save e mail attachments (excel) and found the following code in
"outlookcode" site, but it is stopping at DIM my OlAPP As New
Outlook.Application
I'm getting an error message that reads: Identifier user type- Not identified
I am using Microsoft Outlook 2003.  I posted a question on Outlookcode but
haven't get an answer.  Can anybody help, please?

'Declaration
   Dim myItems, myItem, myAttachments, myAttachment As Object
   Dim myOrt As String
   Dim myOlApp As New Outlook.Application
   Dim myOlExp As Outlook.Explorer
   Dim myOlSel As Outlook.Selection
   
   'Ask for destination folder
   myOrt = InputBox("Destination", "Save Attachments", "C:\ZIFFO\")

   On Error Resume Next
   
   'work on selected items
   Set myOlExp = myOlApp.ActiveExplorer
   Set myOlSel = myOlExp.Selection
   
   'for all items do...
   For Each myItem In myOlSel
   
       'point on attachments
       Set myAttachments = myItem.Attachments
       
       'if there are some...
       If myAttachments.Count > 0 Then
       
           'add remark to message text
           myItem.Body = myItem.Body & vbCrLf & _
               "Removed Attachments:" & vbCrLf
               
           'for all attachments do...
           For i = 1 To myAttachments.Count
           
               'save them to destination
               myAttachments(i).SaveAsFile myOrt & _
                   myAttachments(i).DisplayName

               'add name and destination to message text
               myItem.Body = myItem.Body & _
                   "File: " & myOrt & _
                   myAttachments(i).DisplayName & vbCrLf
                   
           Next i
           
           'for all attachments do...
           While myAttachments.Count > 0
           
               'remove it (use this method in Outlook XP)
               'myAttachments.Remove 1
               
               'remove it (use this method in Outlook 2000)
               myAttachments(1).Delete
               
           Wend
           
           'save item without attachments
           myItem.Save
       End If
       
   Next
   
   'free variables
   Set myItems = Nothing
   Set myItem = Nothing
   Set myAttachments = Nothing
   Set myAttachment = Nothing
   Set myOlApp = Nothing
   Set myOlExp = Nothing
   Set myOlSel = Nothing
Leith Ross - 24 Jan 2006 00:45 GMT
Hello Jaime,

Try this method. It uses late binding.

Dim MyolApp As Object
Set MyolApp = CreateObject("Outlook.Application")

Sincerely,
Leith Ros
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.