Public Sub SearchInOutlook()
Dim CurCell As Range
For Each CurCell In Selection
Call OutlookLaunch(CurCell.Value)
Next
End Sub
Private Sub OutlookLaunch(SearchString As String)
Dim outlookApp As Outlook.Application
Dim olNs As Outlook.Namespace
Dim Fldr As Outlook.MAPIFolder
Dim olMail As Variant
Dim dtToday As Date
dtToday = Date
'Call GetEmailFromNonDefaultInbox
Dim myOlApp As New Outlook.Application
Dim myNameSpace As Outlook.Namespace
Dim myInbox As Outlook.MAPIFolder
Dim myitems As Outlook.Items
Dim strFilter As String
Set myAccounts = myOlApp.GetNamespace("MAPI").Stores
For i = 1 To myAccounts.Count
If myAccounts.Item(i).DisplayName = "myspecificemailbox@gmail.com" Then
Set myInbox = myAccounts.Item(i).GetDefaultFolder(olFolderInbox)
Exit For
End If
Next
Set myitems = myInbox.Items
For Each olMail In myitems
If (InStr(1, olMail.Subject, SearchString, vbTextCompare) > 0) Then
olMail.Display
Exit For
End If
Next
End Sub
So far this script will find the email i selected in excel but it will only find it if it is in the main email folder "Inbox".
I need this script to look through every subfolder in myspecificemailbox@gmail.com to find my emails.
using any default inbox scripts will not work as this is not my default inbox.
any help is appreciated thank you.
Dim CurCell As Range
For Each CurCell In Selection
Call OutlookLaunch(CurCell.Value)
Next
End Sub
Private Sub OutlookLaunch(SearchString As String)
Dim outlookApp As Outlook.Application
Dim olNs As Outlook.Namespace
Dim Fldr As Outlook.MAPIFolder
Dim olMail As Variant
Dim dtToday As Date
dtToday = Date
'Call GetEmailFromNonDefaultInbox
Dim myOlApp As New Outlook.Application
Dim myNameSpace As Outlook.Namespace
Dim myInbox As Outlook.MAPIFolder
Dim myitems As Outlook.Items
Dim strFilter As String
Set myAccounts = myOlApp.GetNamespace("MAPI").Stores
For i = 1 To myAccounts.Count
If myAccounts.Item(i).DisplayName = "myspecificemailbox@gmail.com" Then
Set myInbox = myAccounts.Item(i).GetDefaultFolder(olFolderInbox)
Exit For
End If
Next
Set myitems = myInbox.Items
For Each olMail In myitems
If (InStr(1, olMail.Subject, SearchString, vbTextCompare) > 0) Then
olMail.Display
Exit For
End If
Next
End Sub
So far this script will find the email i selected in excel but it will only find it if it is in the main email folder "Inbox".
I need this script to look through every subfolder in myspecificemailbox@gmail.com to find my emails.
using any default inbox scripts will not work as this is not my default inbox.
any help is appreciated thank you.