Alphacharly Posted February 17, 2011 Share Posted February 17, 2011 Good Day, I have my folder structure in Outlook 2007 and I want to delete the email items in each folder structure but keep the folder structure as is it. Is there any code in Autoit to do that~? Please help. Thanks in advance. Regards Link to comment Share on other sites More sharing options...
Juvigy Posted February 17, 2011 Share Posted February 17, 2011 Why do you need autoit code for that ? Just start AutoArchive and choose a date in the future. Link to comment Share on other sites More sharing options...
water Posted February 17, 2011 Share Posted February 17, 2011 Or you could have a look at wooltown's - function _OutlookDeleteMail. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
Alphacharly Posted February 17, 2011 Author Share Posted February 17, 2011 Thanks. Actually I want to run a macro:- Sub DeleteFolderContents() Dim intIndex As Integer For intIndex = Application.ActiveExplorer.CurrentFolder.Items.Count To 1 Step -1 Application.ActiveExplorer.CurrentFolder.Items(intIndex).delete Next End Sub But this deletes the mail in a selected folder and not all the mails in the folder tree. I have folders to save the messages with lots of sub-folders and sub folders. Is their any way I can use Auto it. I tried outlook.UDF and delete mail option but i dont know hot to go about it. Any help will be useful. Thanks Link to comment Share on other sites More sharing options...
Alphacharly Posted February 17, 2011 Author Share Posted February 17, 2011 Thanks. Actually I want to run a macro:- Sub DeleteFolderContents() Dim intIndex As Integer For intIndex = Application.ActiveExplorer.CurrentFolder.Items.Count To 1 Step -1 Application.ActiveExplorer.CurrentFolder.Items(intIndex).delete Next End Sub But this deletes the mail in a selected folder and not all the mails in the folder tree. I have folders to save the messages with lots of sub-folders and sub folders. Is their any way I can use Auto it. I tried outlook.UDF and delete mail option but i dont know hot to go about it. Any help will be useful. Thanks Link to comment Share on other sites More sharing options...
water Posted February 18, 2011 Share Posted February 18, 2011 (edited) You could use something like this (code snipped from the new Outlook UDF):expandcollapse popup; #FUNCTION# ==================================================================================================================== ; Name...........: _OL_FolderDelete ; Description ...: Deletes a folder, all subfolders and all contained items. ; Syntax.........: _OL_FolderDelete($oOL, $sOL_Folder[, $fOL_Flags = 0]) ; Parameters ....: $oOL - Outlook object returned by a preceding call to _OL_Open() ; $oOL_Folder - Folder object as returned by _OL_FolderAccess or full name of folder to be deleted ; $fOL_Flags - Optional: Specifies what should be deleted. Can be a combination of the following: ; |0: Deletes the folder, all subfolders and all contained items (default) ; |1: Deletes all items (but no folders) in the specified folder ; |2: Recursively deletes all items (but no folders) in the specified folder and all subfolders ; |4: Deletes all subfolders and their items in the specified folder (but not the items in the specified folder) ; Return values .: Success - 1 ; Failure - Returns 0 and sets @error: ; |1 - Error accessing specified folder. See @extended for the error code of _OL_AccessFolder ; |2 - Folder could not be deleted. See @extended for COM error code ; |3 - Folder has not been specified or is empty ; |4 - Subfolder could not be deleted. See @extended for COM error code ; |5 - Item could not be deleted. See @extended for COM error code ; Author ........: water ; Modified.......: ; Remarks .......: Flag usage: ; To the empty the trash folder (or any Outlook system folder) and delete all items plus all subfolders use $fOL_Flags = 5 ; To delete all items in all folders and subfolders but retain the folder structure use $fOL_Flags = 3 ; Related .......: ; Link ..........: ; Example .......: Yes ; =============================================================================================================================== Func _OL_FolderDelete($oOL, $oOL_Folder, $fOL_Flags = 0) If $oOL_Folder = "" Then Return SetError(3, 0, 0) If Not IsObj($oOL_Folder) Then Local $aOL_Temp = _OL_FolderAccess($oOL, $oOL_Folder) If @error <> 0 Then Return SetError(1, @error, 0) $oOL_Folder = $aOL_Temp[1] EndIf ; Delete the folder, all subfolders and all contained items If $fOL_Flags = 0 Then $oOL_Folder.Delete If @error <> 0 Then Return SetError(2, @error, 0) Return 1 EndIf ; Delete items recursively If BitAND($fOL_Flags, 2) = 2 Then For $oOL_SubFolder In $oOL_Folder.Folders $aOL_Temp = _OL_FolderDelete($oOL, $oOL_SubFolder, $fOL_Flags) If @error <> 0 Then Return SetError(2, @error, "") Next EndIf ; Just delete all items in the specified folder If BitAND($fOL_Flags, 1) = 1 Or BitAND($fOL_Flags, 2) = 2 Then For $iOL_Index = $oOL_Folder.Items.Count To 1 Step -1 $oOL_Folder.Items($iOL_Index).Delete If @error <> 0 Then Return SetError(5, @error, 0) Next EndIf ; Delete all subfolders and all contained items If BitAND($fOL_Flags, 4) = 4 Then For $iOL_Index = $oOL_Folder.Folders.Count To 1 Step -1 $oOL_Folder.Folders($iOL_Index).Delete If @error <> 0 Then Return SetError(4, @error, 0) Next EndIf Return 1 EndFunc ;==>_OL_FolderDelete Call it like: $oOutlook = ObjCreate("Outlook.Application") $iResult = _OL_FolderDelete($oOutlook, $oOutlook.ActiveExplorer.CurrentFolder, 3) Edited February 19, 2011 by water My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
Alphacharly Posted February 20, 2011 Author Share Posted February 20, 2011 Thanks for help. However, I get error : ERROR: _OL_FolderAccess(): undefined function. Local $aOL_Temp = _OL_FolderAccess($oOL, $oOL_Folder) Do I need to specify the folder name? Link to comment Share on other sites More sharing options...
Alphacharly Posted February 20, 2011 Author Share Posted February 20, 2011 Thanks for help. However, I get error : ERROR: _OL_FolderAccess(): undefined function. Local $aOL_Temp = _OL_FolderAccess($oOL, $oOL_Folder) Do I need to specify the folder name? Thanks.. Link to comment Share on other sites More sharing options...
water Posted February 20, 2011 Share Posted February 20, 2011 As you pass the folder as an object you can uncomment the line. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
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