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:
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:
and$Inbox = $ns->GetDefaultFolder(olFolderInbox); #Set Inbox = ns.GetD +efaultFolder(olFolderInbox)
andif ($Inbox->Items->$Count = 0) { #If Inbox.Items.Count = 0 T +hen
The bit of code in question is:foreach ($Inbox->Items){ #For Each Item In Ibox.Items
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.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
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: How do I convert VBA script to Perl? - Using Win32::OLE
by marto (Cardinal) on Jan 24, 2006 at 15:44 UTC | |
| |
Re: How do I convert VBA script to Perl? - Using Win32::OLE
by murugu (Curate) on Jan 24, 2006 at 15:57 UTC | |
Re: How do I convert VBA script to Perl? - Using Win32::OLE
by serf (Chaplain) on Jan 24, 2006 at 15:48 UTC | |
Re: How do I convert VBA script to Perl? - Using Win32::OLE
by pKai (Priest) on Jan 24, 2006 at 17:50 UTC | |
| |
Re: How do I convert VBA script to Perl? - Using Win32::OLE
by ikegami (Patriarch) on Jan 24, 2006 at 16:17 UTC | |
|
Back to
Seekers of Perl Wisdom