Sign in to follow this  
Followers 0
Alphacharly

Mail Items in Outlook folders

9 posts in this topic

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

Share this post


Link to post
Share on other sites



Why do you need autoit code for that ? Just start AutoArchive and choose a date in the future.

Share this post


Link to post
Share on other sites

Or you could have a look at wooltown's - function _OutlookDeleteMail.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

You could use something like this (code snipped from the new Outlook UDF):

; #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 by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

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..

Share this post


Link to post
Share on other sites

As you pass the folder as an object you can uncomment the line.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0