Consulting

Results 1 to 6 of 6

Thread: Copy email contents to new email whilst saving attachment.

  1. #1
    VBAX Regular
    Joined
    Sep 2012
    Posts
    9
    Location

    Copy email contents to new email whilst saving attachment.

    This one I think will be impossible, but I will ask anyway in the hope.
    At work we used to use Windows XP and Office 2003. Previously we would receive emails with attached PDF forms. We could double click the attachment, edit the form, save and then forward or reply with attachment with minimal fuss.
    Now on this "new" system of Windows 7 and Office 2010, this is impossible. The only way we can do this is to save the PDF to some location, open, edit, save, forward and attach to new message. With some emails containing up to 10 PDFS and emails coming in all day, this longer approach is taking forever.

    At the press of the button I would ideally love outlook to:

    Copy contents of email to a new email, with addresses, subject line all intact.
    Auto save attachment to hard drive and re-attach to the new email.
    We could then double click the PDF (in theory we should be able to edit it) edit the pdf, save and then we can send.
    Is any of this possible?

    The issue is, the work PC's are tightly locked down, the installation/removal of anything is near impossible. I've tried every guide I can find on the net to edit attachments and nothing works.
    The only thing I can use at work is VBA, which hopefully, will help.

  2. #2
    If PDF is properly associated with Adobe Reader (or Acrobat) then you should still be able to double click the attachment and it would open in that application. You can then save it and do what you want with it. It's been a long time since I used Outlook 2003, but I don't recall it being different? Nor do I see how your proposed process is going to make any difference. If you double click the attachment, it is the attachment embedded in the message that's opening not the one you have saved to the hard drive. It would appear that your process simply duplicates the original message. That is possible of course, but I don't see where it helps?
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  3. #3
    VBAX Regular
    Joined
    Sep 2012
    Posts
    9
    Location
    From what I can see, previously, we doubled clicked the pdf, which opening it in reader 7. Edited the required form fields and hit save, overriding the attachment. Then we would forward it. We wouldn't have to faff about saving to a location and re-attaching it.
    Which seems to be the base with our new setup.
    While I admit the new way of working isn't overly long, when there are dozens of emails to wade through, it does become tiresome.

  4. #4
    In Outlook 2003 double clicking creates a temporary file which for PDF is what is displayed in Adobe Reader. If you edit that file, earlier versions allowed you to save the temporary file, whereas in recent versions the file is read-only. This was deliberately introduced to attempt to avoid the data loss that was prevalent when people saved to a temporary file. I don't recall that the saved temporary file was updated in the message itself, and it certainly isn't in current versions.

    Assuming you are always forwarding to the same location, the following macro may help. From the original message, save the attachment(s) to the preferred location in the macro (here shown as "C:\Path\"). Make your edits and save. Then with the message still selected, run the macro which will create a forwarding message with the revised attachment(s).

    Option Explicit
    
    Sub ForwardUpdatedPDF()
    Const strPath As String = "C:\Path\"        'The location where the attachment was saved
    Const strTo As String = "someone@somewhere.com"        'the recipient
    Dim i As Long
    Dim olInsp As Inspector
    Dim wdDoc As Object
    Dim oRng As Object
    Dim olItem As MailItem
    Dim olUpdatedItem As MailItem
    Dim strPDFName As String
    Dim strMissing As String
        strMissing = ""
        Set olItem = ActiveExplorer.Selection.Item(1)
        Set olUpdatedItem = olItem.Forward
        With olUpdatedItem
            .To = "someone@somewhere.com"
            Set olInsp = .GetInspector
            Set wdDoc = olInsp.WordEditor
            Set oRng = wdDoc.Range(0, 0)
            .Display
            oRng.Text = "Updated PDF attached"
        End With
        For i = olUpdatedItem.Attachments.Count To 1 Step -1
            If LCase(Right(olUpdatedItem.Attachments.Item(i).FileName, 3)) = "pdf" Then
                strPDFName = olUpdatedItem.Attachments.Item(i).FileName
                olUpdatedItem.Attachments.Remove (i)
                If FileExists(strPath & strPDFName) Then
                    olUpdatedItem.Attachments.Add strPath & strPDFName
                Else
                    strMissing = strMissing & strPath & strPDFName & vbCr
                End If
            End If
        Next i
        If Not strMissing = "" Then
            MsgBox "The PDF file(s)" & vbCr & strMissing & _
                   "do(es) not exist!"
        End If
    lbl_Exit:
        Set olItem = Nothing
        Set olUpdatedItem = Nothing
        Set olInsp = Nothing
        Set wdDoc = Nothing
        Set oRng = Nothing
        Exit Sub
    End Sub
    
    Private Function FileExists(filespec) As Boolean
    Dim fso As Object
        Set fso = CreateObject("Scripting.FileSystemObject")
        If fso.FileExists(filespec) Then
            FileExists = True
        Else
            FileExists = False
        End If
    lbl_Exit:
        Exit Function
    End Function
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  5. #5
    VBAX Regular
    Joined
    Sep 2012
    Posts
    9
    Location
    Thanks so much for this. I was hoping however that the script would (if possible) save the PDF to a designated location and then re-add this to the email, so when someone double clicked it, the new saved version would open, allowing editing.

    The workflow would be:
    Recieve email (the person it comes from does indeed vary).
    Click macro button
    This would copy the contents, with subject and addressee to a new email, whilst also saving the attachment to the hard drive and re attaching it. It would happen fast enough that the user would not know the difference from the old way.
    We could then open the attachment, edit the PDF, click save and then send.

    This would stop the need to currently:
    Get email
    Open PDF
    Make changes and click save
    Be told to save to another location
    Save the file
    Original message, click reply/forward
    find the now saved PDF and attach
    Send

    It may not seem much to others, but when we can get 50+ emails in a day, some with 10+ attachments, this "new" way of working is a real pain.

  6. #6
    As I said earlier, I don't see how this helps. The path from which the attachment was added is not stored with the attachment. The attachment is embedded in the message, so in effect would be a duplicate of the original message. Double clicking that message would open it in an appropriate application. Any saves are not saved back to the embedded attachment, but to a location of your choosing. The macro simply removes part of the process in that it allows a PDF that has already been saved and edited to be forwarded using fewer steps.

    You report that you were previously able to edit the attachment directly. Frankly I don't recall this ever being possible, but I don't have the old software available to check. I do however recall lots of people complaining about losing saved attachment edits (and I have a web page dedicated to finding those edits in the older version), which is why Microsoft made it difficult to save the attachment without providing a location.
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

Posting Permissions

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