View Single Post
 
Old 01-28-2023, 03:14 AM
gmayor's Avatar
gmayor gmayor is offline Windows 10 Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

The following should work.


Code:
Sub ReAttach()
Dim olItem As MailItem
Dim olAtt As Attachment
Dim sName As String
Dim sPath As String
Dim cNames As Collection
Dim i As Long

    sPath = Environ("TEMP") & "\"
    On Error Resume Next
    Select Case Outlook.Application.ActiveWindow.Class
        Case olInspector
            Set olItem = ActiveInspector.currentItem
        Case olExplorer
            Set olItem = Application.ActiveExplorer.Selection.Item(1)
    End Select
    olItem.Save
    Set cNames = New Collection
    If olItem.Attachments.Count > 0 Then
        For i = olItem.Attachments.Count To 1 Step -1
            Set olAtt = olItem.Attachments(i)
            sName = olAtt.FileName
            If Not sName Like "image*.jpg" Then
                sName = Replace(olAtt.FileName, "%20", " ")
                olAtt.SaveAsFile sPath & sName
                cNames.Add sPath & sName
                olAtt.Delete
            End If
        Next i
        For i = 0 To cNames.Count
            'Debug.Print cNames(i)
            olItem.Attachments.Add cNames(i)
            Kill cNames(i)
        Next i
    End If
lbl_Exit:
    Set olItem = Nothing
    Set olAtt = Nothing
    Set cNames = Nothing
    Exit Sub
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote