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.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|