Jump to content

Recommended Posts

Posted

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

Posted

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

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

 

Posted

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

Posted

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

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

 

Posted

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?

Posted

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

Posted

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

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

 

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
×
×
  • Create New...