Hi, I'm trying to combine 2 VBA found at other source to reply an email.
VBA is to filter column "F" with text "email". Then locate emails subject at column "A" and use Outlook filter to reply with latest email received.
The first email run success to display but fail to call second line from my worksheet.
Below is my code.
Dim OutlookApp As Object
Dim OutMail As Object
Dim Cell As Range
' Outlook's constant
Const olFolderSentMail = 5
Dim IsOutlookCreated As Boolean
Dim sFilter As String, sSubject As String
Application.ScreenUpdating = False
On Error GoTo cleanup
For Each Cell In Columns("F").Cells.SpecialCells(xlCellTypeConstants)
If Cell.Value Like "email" Then
' Get/create outlook object
On Error Resume Next
Set OutlookApp = GetObject(, "Outlook.Application")
If Err Then
Set OutlookApp = CreateObject("Outlook.Application")
IsOutlookCreated = True
On Error GoTo 0
' Restrict items
sSubject = Cells(Cell.Row, "A").Value 'ActiveCell.Value
sFilter = "[Subject] = '" & sSubject & "'"
With OutlookApp.Session.GetDefaultFolder(olFolderInbox).Folders("ML").Items.Restrict(sFilter) 'error here :run-time error '440'
If .Count > 0 Then
.Sort "ReceivedTime", True
MsgBox "No emails found with Subject:" & vbLf & "'" & sSubject & "'"
' Quit Outlook instance if it was created by this code
If IsOutlookCreated Then
Set OutlookApp = Nothing
Set OutApp = Nothing
Application.ScreenUpdating = True