Hi Team,
Below outlook code works, Need help in converting Early binding outlook code to late Binding.
Task was Red flagged emails needs to attach to new email.
Public filename As String
Thanks
mg
T
Below outlook code works, Need help in converting Early binding outlook code to late Binding.
Task was Red flagged emails needs to attach to new email.
Public filename As String
VBA Code:
Sub Draft_Red_Flagged_emails()
Dim Outlook_F_Path As String
Outlook_F_Path = mac.Range("b4").Value 'Outlook folder path Example'\\abc@gmail.com\Inbox
StartTime = Timer
'Early Binding outlook
Dim olApp As Outlook.Application
Set olApp = New Outlook.Application
Dim Main_Folder As Folder
'Calling Function for outlook
Set Main_Folder = GetOLFolder(Outlook_F_Path, olApp)
Dim objMail As Outlook.MailItem
Dim Item As Object
Dim olItem As MailItem
Dim objMsg As MailItem
Set objMsg = olApp.CreateItem(olMailItem)
Dim Filtered_Results As Object
'Apply filter in outlook
SFILTER = "[ReceivedTime]>'" & Format(Date, "DDDDD HH:NN") & "'"
Set Filtered_Results = Main_Folder.Items.Restrict(SFILTER)
'Date and Time for subject line
T1 = Format(TimeValue(Now), "hh:mm AM/PM")
D = Format(Date, "DD") & "/" & Format(Date, "MM") & "/" & Format(Date, "YYYY")
'Check all mailItem which has Red Flag in search results (Restrict)
For Each Item In Filtered_Results
If TypeOf Item Is Outlook.MailItem Then
MailRT = Item.ReceivedTime
flagclr = Item.FlagIcon
If flagclr = 6 Then
'3am to 2:30pm
'If TimeValue(currTime) >= TimeValue("3:00:00") And TimeValue(currTime) < TimeValue("14:30:00") Then
If TimeValue(MailRT) >= mac.Range("A15").Value And TimeValue(MailRT) < mac.Range("B15").Value Then
With objMsg
.To = mac.Range("a10").Value
.CC = mac.Range("b10").Value
.Body = "Hi All," & vbNewLine & mac.Range("d11").Value
.Subject = mac.Range("c10").Value & " " & "(" & T1 & ")" & " - " & D 'Add Date and time to subject
.Attachments.Add Item
.Display
'.send
End With
End If
End If
End If
Next
MsgBox "Macro Successful Time Taken " & Format(Timer - StartTime, "00:00") & " Seconds"
End Sub
Sub PickOutlookFolder()
Dim objNS As Namespace
Dim objFolder As Object
Dim strFolderPath As String
Dim strEntryID As String
'Set Outlook Object
Set objNS = Outlook.GetNamespace("MAPI")
Set objFolder = objNS.PickFolder
If TypeName(objFolder) <> "Nothing" Then
strFolderPath = objFolder.Folderpath
strEntryID = objFolder.EntryID
End If
mac.Range("b4").Value = strFolderPath
End Sub
Function GetOLFolder(ByVal Folderpath As String, olApp As Outlook.Application) As Outlook.Folder
'Convert a string folder path to actual folder object, which lets you retrieve various folder properties
Dim TestFolder As Outlook.Folder
Dim FoldersArray As Variant
Dim i As Integer
On Error GoTo GetFolder_Error
If Left(Folderpath, 2) = "\\" Then
Folderpath = Right(Folderpath, Len(Folderpath) - 2)
End If
'Convert folderpath to array
FoldersArray = Split(Folderpath, "\")
Set TestFolder = olApp.Session.Folders.Item(FoldersArray(0))
If Not TestFolder Is Nothing Then
For i = 1 To UBound(FoldersArray, 1)
Dim SubFolders As Outlook.Folders
Set SubFolders = TestFolder.Folders
Set TestFolder = SubFolders.Item(FoldersArray(i))
If TestFolder Is Nothing Then
Set GetOLFolder = Nothing
End If
Next
End If
'Return the TestFolder
Set GetOLFolder = TestFolder
Exit Function
GetFolder_Error:
Set GetOLFolder = Nothing
Exit Function
End Function
Thanks
mg
T