user3773028
user3773028

Reputation:

How can I open with VBA a attachment of excel file and verify inside the file before seva the message in a determined folder in outlook?

I receive determined e-mails with an attached excel file and I need to know if this email is part of a process before moving it to a determined folder.

  1. The macro starts when an email arrives.
  2. The macro verifies if the email has an excel attachment.
  3. If it's an Excel file, the macro verifies if inside the file the first cell contains the word "process".
  4. If that is true, the macro moves the email to a determined folder in Outlook.

I can do the first and second step, but I don't know if it's possble to open a excel file attachment and verify the first cell.

Upvotes: 0

Views: 2993

Answers (1)

Nathan_Sav
Nathan_Sav

Reputation: 8531

Called from a rule.

Sub TEST1(o As Outlook.MailItem)

    Dim xl As Excel.Application

    If InStr(1, o.Attachments(1), ".xls") > 0 Then

        Set xl = New Excel.Application
        xl.Visible = 1
        '    Save the attachment here as strAttachmentName
        xl.Workbooks.Open strAttachmentName
        If xl.ActiveWorkbook.Worksheets(1).Range("a1").Value = "Processing" Then
            o.Move Application.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox)
        End If

    End If

End Sub

Upvotes: 0

Related Questions