I have the path name and file names in Col E
I have tried to write code which is pasted in the sheet module to be able to double click on any of the cells and to generate an email and attah the file
When I double click a cell nothing happens
See my code below
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Dim objOutlook As Object
Dim objMail As Object
Dim filePath As String
Dim fileName As String
Dim subject As String
Dim body As String
'Check if the double-clicked cell is in column E
If Target.Column = 5 Then ' Change to 5 for column E
'Get the file path from the double-clicked cell
filePath = "'" & Target.Value & "'"
'Check if the file path exists
If Dir(filePath) <> "" Then
'Initialize Outlook application
Set objOutlook = CreateObject("Outlook.Application")
Set objMail = objOutlook.CreateItem(0) 'Create a new email
'Extract the file name from the file path
fileName = Right(filePath, Len(filePath) - InStrRev(filePath, "\"))
MsgBox filePath
'Set email subject and body
subject = "Bank Confirmation letter"
body = "Dear Sirs," & vbCrLf & vbCrLf & "Please find attached the bank confirmation letter." & vbCrLf & vbCrLf & "Regards," & vbCrLf & "Howard"
'Create the email and attach the file
With objMail
.To = ""
.subject = subject
.body = body
.Attachments.Add filePath 'Attach the file
'Display the email
.Display
End With
'Clean up
Set objMail = Nothing
Set objOutlook = Nothing
Cancel = True 'Prevent default double-click behavior
End If
End If
End Sub
Bookmarks