Results 1 to 7 of 7
  1. #1
    Star Lounger
    Join Date
    Mar 2001
    Location
    Atlanta, Georgia, USA
    Posts
    64
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How to copy an attachment

    This one has me stumped. I'm trying to use VB scripting within Outlook 2000 to programmatically take an e-mail message and copy all of its contents to a new message. Everything is working except for copying attachments. I can tell how many attachments are in the original, and determine all the information about each attachment. But I cannot find the correct code to copy the attachments to the new piece of e-mail. Before you ask, no, this is not for an e-mail virus!

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: How to copy an attachment

    Looks as though you may need to use the Attachment.SaveAs method, to store the attachments in some temporary location. To retrieve the path to the user's temp folder:

    (1) Set a reference to the Microsoft Scripting Runtime

    (2) Use the GetSpecialFolder method:

    Dim objFS As New Scripting.FileSystemObject, strTempPath As String
    strTempPath = objFS.GetSpecialFolder(TemporaryFolder)

    That should be a reasonably safe place to drop the files, but you could always give them a unique name as well.

  3. #3
    Platinum Lounger
    Join Date
    Jan 2001
    Location
    Roanoke area, Virginia, USA
    Posts
    3,729
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: How to copy an attachment

    see <A target="_blank" HREF=http://www.slipstick.com>slipstick</A> for the VB code needed.

  4. #4
    3 Star Lounger siflaar's Avatar
    Join Date
    Jan 2001
    Location
    Amersfoort, Netherlands
    Posts
    203
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Re: How to copy an attachment

    Hello Briana,

    I know you want to program it, but will a simple Forward not doing it all for you?
    Greetings,

    Patrick Schouten
    (The Netherlands)

  5. #5
    Star Lounger
    Join Date
    Mar 2001
    Location
    Atlanta, Georgia, USA
    Posts
    64
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: How to copy an attachment

    I want to thank everyone for the assistance. Since I couldn't do a simple forward,(which I tried first, by the way), it was beginning to be a bit of a problem. Here's my solution:

    Private Sub Copy_Attachments(FromMail As MailItem, ToMail As MailItem)
    Dim i As Integer
    Dim SavedName As String

    For i = 1 To FromMail.Attachments.Count
    With FromMail
    If FromMail.Attachments.Count > 0 Then
    SavedName = "C:" & FromMail.Attachments.Item(i).FileName
    FromMail.Attachments.Item(i).SaveAsFile SavedName
    ToMail.Attachments.Add SavedName
    Kill SavedName
    End If
    End With
    Next
    End Sub


    Again, thanks!

  6. #6
    Platinum Lounger
    Join Date
    Jan 2001
    Location
    Roanoke area, Virginia, USA
    Posts
    3,729
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: How to copy an attachment

    were you wanting to forward as attachment but had it set to forward inline? you can change the option is tools > option. also, if you select multiple messages and choose forward they go as attachment, just delete theextra ones.

  7. #7
    Star Lounger
    Join Date
    Mar 2001
    Location
    Atlanta, Georgia, USA
    Posts
    64
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: How to copy an attachment

    What I am doing is writing an Outlook-driven PDL that requires no signup. When a message comes in, my PDL application finds the manager(s) that the message is from, then looks up their entire reporting structure in the corporate database and builds a BCC list. It then sends a copy of the message out to everyone on the list. I tried the FORWARD function, but for some reason, I kept getting an error from my Exchange server about permissions. I fixed that by making a copy of the message and sending the copy, rather than the original.

    The attachments was the last major hurdle. Aside from testing, it seems to be ready for release.

Posting Permissions

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