When I composed an outgoing email message, THEN I want ta add a specific file (C:\path\file1.pdf) to this message.
Ho do I solve this issue?
Most of the VBA codes uses a new message + file. I want to add 1 fixed file.
When I composed an outgoing email message, THEN I want ta add a specific file (C:\path\file1.pdf) to this message.
Ho do I solve this issue?
Most of the VBA codes uses a new message + file. I want to add 1 fixed file.
The following will add the named file to the currently open message
Sub AddAttachment() 'Graham Mayor - https://www.gmayor.com - Last updated - 18 May 2020 Const strPath As String = "C:\path\file1.pdf" Dim olMsg As MailItem On Error Resume Next Select Case Outlook.Application.ActiveWindow.Class Case olInspector Set olMsg = ActiveInspector.currentItem Case Else End Select If TypeName(olMsg) = "MailItem" Then If FileExists(strPath) Then olMsg.Attachments.Add strPath Else Beep MsgBox "Attachment file not forund" End If Else Beep MsgBox "No mail item selected" End If lbl_Exit: Exit Sub End Sub Private Function FileExists(strFullName As String) As Boolean 'Graham Mayor 'strFullName is the name with path of the file to check Dim FSO As Object Set FSO = CreateObject("Scripting.FileSystemObject") If FSO.FileExists(strFullName) Then FileExists = True Else FileExists = False End If lbl_Exit: Set FSO = Nothing 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