robertocm Posted yesterday at 04:49 PM Posted yesterday at 04:49 PM (edited) Thanks! Sorry i'm a little lost, perharps in some days i can see it more clear First all mails are unmarked ("blank"), then i save attachements, and expect to leave all mails finally marked as completed (green check) Next day we check the folder again looking for new mails (pending to save attachments, then unmarked or "blank") If i use your new funcion, is like cancelling the previous line: not the expected change from "blank" to "green" (is like nothing happens) _OL_ItemModify($oOutlook, $aItems[$i][1], "", "TaskCompletedDate=09/07/2026") _OL_ItemTaskUnmark($aItems[$i][1]) But heat wave in spain ... 😅 Edited yesterday at 05:05 PM by robertocm
robertocm Posted 17 hours ago Posted 17 hours ago (edited) I would suggest a new function similar to this: Func _OL_ItemMarkAsTask($vItem, $OlMarkInterval) $vItem.MarkAsTask($OlMarkInterval) $vItem.Save() EndFunc ;==>_OL_ItemTaskMarkAsTask An example tested ok: second run doesn't return any mails and all showing the green flag after saving attachments #include <OutlookEx.au3> Global $oOutlook, $aMailFolder ; Set the error handler _OL_ErrorNotify(2) $oOutlook = _OL_Open() ; Get the Inbox object $aMailFolder = _OL_FolderAccess($oOutlook, "", $olFolderInbox) ;Filtering emails without marks, then save the attachments, finally mark them as completed (green flag) ;https://www.autoitscript.com/forum/topic/126305-outlookex-udf/page/43/#findComment-1553738 $aItems = _OL_ItemFind($oOutlook, $aMailFolder[1], $olMail, "", "IsMarkedAsTask", "False", "Subject,@ItemObject,IsMarkedAsTask,TaskDueDate", "", 8) If @error = 0 Then _ArrayDisplay($aItems) Else MsgBox($MB_ICONERROR, "OutlookEX UDF", "_OL_ItemFind returned an error. @error = " & @error & ", @extended: " & @extended) Exit EndIf If $aItems[0][0] > 0 Then ;Loop through every email found For $i = 1 To $aItems[0][0] ;Help File: _OL_ItemFind / Remarks: @ItemObject - Object of the item that matches the search criteria Global $oItem = $aItems[$i][1] ;Save the attachments ... ;Mark as completed ;https://learn.microsoft.com/en-us/office/vba/api/outlook.mailitem.markastask _OL_ItemMarkAsTask($oItem, $olMarkComplete) Next EndIf Thanks for your patience Edited 16 hours ago by robertocm
water Posted 15 hours ago Author Posted 15 hours ago My (incomplete) understanding is: We need a function to create a task from an item (_OL_ItemTaskMark). This method sets the value of several other properties, depending on the value provided in MarkInterval. When a mail has been marked as task you can change this new properties using _OL_ItemModify. To unmark a task another function is needed (_OL_ItemTaskUnmark). I guess that all properties created by _OL_ItemTaskMark are deleted then (NEED TO CHECK). I noticed that I missed to call the Save Method in _OL_ItemTaskMark. This might be the cause of your problem. The task existed until Outlook was closed (NEED TO CHECK). Here are the latest versions of this two functions: expandcollapse popup; #FUNCTION# ==================================================================================================================== ; Name ..........: _OL_ItemTaskMark ; Description ...: Marks an item as a task and assigns a task interval for the item. ; Syntax.........: _OL_ItemTaskMark($oOL, $vItem, $sStoreID, $iInterval) ; Parameters ....: $oOL - Outlook object returned by a preceding call to _OL_Open() ; $vItem - EntryID or object of the item ; $sStoreID - StoreID where the EntryID is stored. Use the keyword "Default" to use the users mailbox ; $iInterval - Time period for which the item is marked as a task. Defined by the $OlMarkInterval Enumeration ; Return values .: Success - Item object ; Failure - Returns 0 and sets @error: ; |1 - No Outlook item specified ; |2 - Item could not be found. EntryID might be wrong. @extended is set to the COM error ; |3 - $iInterval is not a number ; |4 - Method MarkAsTask returned an error. @extended is set to the COM error ; Author ........: water ; Modified ......: ; Remarks .......: This function sets the value of several other properties, depending on the value provided in $iInterval. ; For more information about the properties set see the link below (OlMarkInterval Enumeration). ; This function supports ContactItem, DistListItem, MailItem, PostItem and SharingItem objects. ; To change this or set further properties please call _OL_ItemModify. ; Related .......: _OL_ItemTaskUnmark ; Link ..........: OlMarkInterval Enumeration: http://msdn.microsoft.com/en-us/library/bb208108(v=office.12).aspx ; Example .......: Yes ; =============================================================================================================================== Func _OL_ItemTaskMark($oOL, $vItem, $sStoreID, $iInterval) If Not IsObj($vItem) Then If StringStripWS($vItem, BitOR($STR_STRIPLEADING, $STR_STRIPTRAILING)) = "" Then Return SetError(1, 0, 0) $vItem = $oOL.Session.GetItemFromID($vItem, $sStoreID) If @error Then Return SetError(2, @error, 0) EndIf If Not IsInt($iInterval) Then SetError(3, 0, 0) $vItem.MarkAsTask($iInterval) If @error Then Return SetError(4, @error, 0) $vItem.Save() Return $vItem EndFunc ;==>_OL_ItemTaskMark ; #FUNCTION# ==================================================================================================================== ; Name ..........: _OL_ItemTaskUnmark ; Description ...: Unmarks an item already marked as a task. ; Syntax.........: _OL_ItemTaskUnmark($oOL, $vItem, $sStoreID) ; Parameters ....: $oOL - Outlook object returned by a preceding call to _OL_Open() ; $vItem - EntryID or object of the item ; $sStoreID - StoreID where the EntryID is stored. Use the keyword "Default" to use the users mailbox ; Return values .: Success - Item object ; Failure - Returns 0 and sets @error: ; |1 - No Outlook item specified ; |2 - Item could not be found. EntryID might be wrong. @extended is set to the COM error ; |3 - Method ClearTaskFlag returned an error. @extended is set to the COM error ; Author ........: water ; Modified ......: ; Remarks .......: Calling this method sets the IsMarkedAsTask property to False. ; Related .......: _OL_ItemTaskMark ; Link ..........: ; Example .......: Yes ; =============================================================================================================================== Func _OL_ItemTaskUnmark($oOL, $vItem, $sStoreID) If Not IsObj($vItem) Then If StringStripWS($vItem, BitOR($STR_STRIPLEADING, $STR_STRIPTRAILING)) = "" Then Return SetError(1, 0, 0) $vItem = $oOL.Session.GetItemFromID($vItem, $sStoreID) If @error Then Return SetError(2, @error, 0) EndIf $vItem.ClearTaskFlag() If @error Then Return SetError(3, @error, 0) $vItem.Save() Return $vItem EndFunc ;==>_OL_ItemTaskUnmark I'll be back as soon as I have finished the tests robertocm 1 My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
water Posted 7 hours ago Author Posted 7 hours ago Func _OL_ItemTaskComplete($olItem) $olItem.FlagStatus = 1 ; 1 = olFlagComplete $olItem.Save Return EndFunc ;==>_OL_ItemTaskComplete This function sets the green check mark. Property FlagStatus (and others) are deprecated. But MS does not explain (at least I haven't found any good documentations) how to replace this properties. This means: Don't rely too much on the deprecated properties. robertocm 1 My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
robertocm Posted 6 hours ago Posted 6 hours ago (edited) 1 hour ago, water said: This function sets the green check mark. I prefer your new udf function that also sets the green check mark, and doesn't use FlagStatus _OL_ItemTaskMark($oOutlook, $oItem, Default, $olMarkComplete) ;OK Thank! Edited 6 hours ago by robertocm
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now