save email from excel


New Member
Outlook version
Outlook 2013 64 bit
Email Account
Dear Sir
wishing you a good day.

we have a Excel VBA code that saves the selected email from outlook and hyperlinks a cell to it. but the problem is when the selected email is from a search result on "All Mailboxes". I would be thankful if you check what the problem is and let me know.

Sub LinkToQuotation()
Dim oMail As Outlook.MailItem
Dim objItem As Object
Dim sPath As String
Dim dtDate As Date
Dim sName As String
Dim enviro As String
enviro = CStr(Environ("USERPROFILE"))
For Each objItem In ActiveExplorer.Selection
Set oMail = objItem
sName = oMail.Subject & ".msg"
ReplaceCharsForFileName sName, " "
sPath = "D:\Dropbox\calc quotations\"
Debug.Print sPath & sName
oMail.SaveAs sPath & sName, olMSG
ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:=sPath & sName, TextToDisplay:="Link to Email"
End Sub

Best Regards