+ Reply to Thread
Results 1 to 2 of 2

[SOLVED] save e mail attachments and remove them

  1. #1
    Jaime
    Guest

    [SOLVED] save e mail attachments and remove them

    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

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258
    Hello Jaime,

    Try this method. It uses late binding.

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

    Sincerely,
    Leith Ross

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1