Jump to content
Sign in to follow this  
JohnBailey

Select all Items or just the first few

Recommended Posts

JohnBailey

Mods: can you please move this to the COM threads area

I know how to invoke some commands and then pull info from Outlook, but only if email is selected. How do a force a certain amount of email to be selected. For instance, the first (most recent) 10 emails in the inbox?

Opt("TrayIconDebug", 1)
Opt("WinSearchChildren", 1)
TrayTip("AutoIt Script", @ScriptName, 60, 1)
HotKeySet("{ESC}", "Terminate")
Func Terminate()
    WinMinimizeAllUndo()
    Exit
EndFunc

#include <File.au3>
#include <Array.au3>
#include <Date.au3>

$oOutlookApp = ObjCreate("Outlook.Application")
If NOT IsObj($oOutlookApp) Then
    MsgBox(0,'',"$oOutlookApp not object")
Else
    $oOutlookExp = $oOutlookApp.ActiveExplorer
    $oOutlookSel = $oOutlookExp.Selection
    For $x = 1 To 5;$oOutlookSel.Count
        Local $getSubjectName = $oOutlookSel.Item($x).Subject
        Local $defaultFileName = StringReplace($getSubjectName,":"," ")
        Local $selectedLocation = @ScriptDir&'\'
        ConsoleWrite($oOutlookSel.Item($x).Subject&@CRLF)
        ;MsgBox(0,'', $oOutlookSel.Item($x).Subject)    ;<---- Subject Line
        ;MsgBox(0,'', $oOutlookSel.Item($x).SenderName) ;<---- Message (Mail) From
        ;ControlSetText('test.txt - Notepad','',"Edit1",$oOutlookSel.Item($x).Body)
        If StringInStr($oOutlookSel.Item($x).Subject,'PAI Managed Accts Report') > 0 Then
            If $oOutlookSel.Item($x).Attachments.Count Then
                Local $oOutlookAttachments = $oOutlookSel.Item($x).Attachments
                Local $attachmentsArray = _ArrayCreate("nothing")
                For $xx = 1 To $oOutlookAttachments.Count
                    $oOutlookAttachments.Item($xx).SaveAsFile($selectedLocation&$oOutlookAttachments.Item($xx).DisplayName)
                    _ArrayAdd($attachmentsArray,$selectedLocation&$oOutlookAttachments.Item($xx).DisplayName)
                    ;MsgBox(0,'',$oOutlookAttachments.Item($xx).DisplayName) ;<---Shows the file name
                    ;MsgBox(0,'',$oOutlookAttachments.Item($xx).FileName) ;<---Shows the file name another method
                Next
            Else
                ;continue to look
            Endif
            
        EndIf
    Next
EndIf

MsgBox(0,'Auto Archiver','Completed', 4)
Edited by JohnBailey

A decision is a powerful thing

Share this post


Link to post
Share on other sites
ptrex
JohnBailey

Maybe this can get you started.

Outlook Archiver

that's really neat! Thank you for dropping that by me!


A decision is a powerful thing

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  

×