Hi,
can the code below can be modify for input box to ask for subject to search instead of stating subject in code:
thank you
can the code below can be modify for input box to ask for subject to search instead of stating subject in code:
VBA Code:
[IMG alt="Question"]https://i1.social.s-msft.com/globalresources/Images/trans.gif?cver=0001[/IMG]
[URL='https://social.msdn.microsoft.com/Forums/Account/Login?ReturnUrl=https%3a%2f%2fsocial.msdn.microsoft.com%3a443%2fForums%2foffice%2fen-US%2f12779a03-4a25-4768-8266-82116ea8eae4%2fsearch-outlook-email-with-excel-vba%3fforum%3doutlookdev%26prof%3drequired'][IMG alt="Sign in to vote"]https://i1.social.s-msft.com/globalresources/Images/trans.gif?cver=0001[/IMG]
1
Sign in to vote[/URL]
A big thank you to Ken, Damian and Dmitry for helping me sort out this matter. For future reference I am posting the code for copying the contents of an Outlook email into an Excel sheet based on email subject (Macro controlled from Excel)
Sub Work_with_Outlook()
Set olApp = CreateObject("Outlook.Application")
Dim olNs As Outlook.Namespace
Dim Fldr As Outlook.MAPIFolder
Dim olMail As Variant
Dim sir() As String
Set olApp = New Outlook.Application
Set olNs = olApp.GetNamespace("MAPI")
Set Fldr = olNs.GetDefaultFolder(olFolderInbox)
Set myTasks = Fldr.Items
[B][COLOR=rgb(226, 80, 65)] Set olMail = myTasks.Find("[Subject] = ""*desired subject*""")[/COLOR][/B]
If Not (olMail Is Nothing) Then
sir = Split(olMail.Body, vbCrLf)
For i = 1 To UBound(sir)
ActiveWorkbook.Sheets("Sheet1").Cells(i, 1).Value = sir(i)
Next i
olMail.Delete
End If
End Sub
thank you