Click here to Skip to main content
15,890,609 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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 how to save an email in outlook when selected email is from search result on "ALL Mailboxes".

What I have tried:

VB
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
        Range("E3").Select
        ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:=sPath & sName,    TextToDisplay:="Link to Email"
    Next
End Sub
Posted
Updated 12-Aug-19 3:00am
v4
Comments
Richard Deeming 22-Jul-19 16:09pm    
You've told us when the problem happens, but you've forgotten to tell us what the problem is.

Click the green "Improve question" link, and update your question with a complete description of the problem. Include the full details of any errors, and remember to indicate which line of code they relate to.
Shahrooz Bral 22-Jul-19 16:14pm    
the problem is it works on a email that you are viewing its inbox but while searching in All mailboxes , it does not work.
my code should be changed but i do not know how.
CHill60 24-Jul-19 4:05am    
"it does not work" is not informative. What actually happens and what are you expecting to happen?

1 solution

Please, read this: Working with All Items in a Folder or Selected Items[^] and change the code to your needs.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900