http://qs321.pair.com?node_id=525200

Win has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks,

Please could monks guide me on converting the VBA script (below) to Perl using Win32::OLE. I do not ask anyone to go through it all. However, guidance on the bits that are not straight forward would be very welcome. For example,the Exit Sub command. Do I just use the 'last' command here? How do I declare these variable types? Do I do it using Win32::OLE or do I do it using standard Perl syntax? A few bits that I have tried to convert are:
$Inbox = $ns->GetDefaultFolder(olFolderInbox); #Set Inbox = ns.GetD +efaultFolder(olFolderInbox)
and
if ($Inbox->Items->$Count = 0) { #If Inbox.Items.Count = 0 T +hen
and
foreach ($Inbox->Items){ #For Each Item In Ibox.Items
The bit of code in question is:
Option Explicit Private Sub Application_NewMail() On Error GoTo GetAttachments_err ' Declare variables Dim ns As NameSpace Dim Inbox As MAPIFolder Dim Item As Object Dim Atmt As Attachment Dim FileName As String Dim i As Integer Set ns = GetNamespace("MAPI") Set Inbox = ns.GetDefaultFolder(olFolderInbox) i = 0 'Check Inbox for messages and exit of none found If Inbox.Items.Count = 0 Then Exit Sub End If ' Check each message for attachments For Each Item In Inbox.Items ' Save any attachments found For Each Atmt In Item.Attachments ' This path must exist! Change folder name as necessary. If Left(Atmt.FileName, 10) = "Flat_file_" Then FileName = "G:\Input\" & Atmt.FileName Atmt.SaveAsFile FileName i = i + 1 End If Next Atmt Next Item 'Clear memory GetAttachments_exit: Set Atmt = Nothing Set Item = Nothing Set ns = Nothing Exit Sub GetAttachments_err: Resume GetAttachments_exit End Sub
This question follows my last one where very good links were offered by monks. Maybe I can execute this block of code in a single go.