in reply to Re^2: How do I convert VBA script to Perl? - Using Win32::OLE
in thread How do I convert VBA script to Perl? - Using Win32::OLE

So we get:

#! perl use strict; use warnings; use File::Spec (); use Win32::OLE qw( in ); use Win32::OLE::Const 'Microsoft Outlook'; my $SAVE_FOLDER = 'G:\Input'; my $Outlook = Win32::OLE->new('Outlook.Application', 'Quit'); Detach_files(); sub Detach_files { my $ns = $Outlook->GetNamespace('MAPI'); my $Inbox = $ns->GetDefaultFolder(olFolderInbox); return if $Inbox->Items->{Count} == 0; foreach my $Item (in $Inbox->Items) { # Check each message for attachments. foreach my $Atmt (in $Item->Attachments) { # Save any "Flat_file_" attachments found. my $FileName = $Atmt->FileName; if ($FileName =~ /^Flat_file_/) { $FileName = File::Spec->catdir($SAVE_FOLDER, $FileName); $Atmt->SaveAsFile($FileName); } } } }

Untested.

Replies are listed 'Best First'.
A reply falls below the community's threshold of quality. You may see it by logging in.
A reply falls below the community's threshold of quality. You may see it by logging in.