Open EML file and extract attachments with separate pst

abenitez77

Board Regular
Joined
Dec 30, 2004
Messages
149
I have some code that opens eml files and extracts the attachments. This works fine, but when I run the code from more than 1 desktop/server, I get an error msg. This is because they all try to use the same pst file that gets created on my network by outlook. I am working in a citrix environment so it goes to my users folder (i.e. z:\users\alex). How can i tell it to create the pst file somewhere else so that each desktop/server will have it's own separate pst that it uses?

This is a piece of my code below:

Code:
 'Open Email File to save XLS file
    ShellExecute Application.hwnd, "Open", MailFile, "", MailFile, SW_SHOWMINIMIZED
    Wait 2
    DoEvents: DoEvents: DoEvents
OpenOutlook:
    DoEvents
    'Gave 3sec wait to open outlook object
    Application.Wait (Now + TimeValue("0:00:03"))
    'Create Outlook object to get email data
    DoEvents
    If OLook Is Nothing Then
        DoEvents
        Set OLook = CreateObject("Outlook.Application")
        DoEvents
    End If
    DoEvents
    'Check here outlook Object is open or not?
    If OLook Is Nothing Then
        DoEvents
        GoTo OpenOutlook
        'If Outlook object is not opened then try again.
    End If
    DoEvents

    Set MailInspect = OLook.ActiveInspector
    DoEvents
    Set MailItem = MailInspect.CurrentItem
    DoEvents
    'Check All attachments
    For Each att In MailItem.Attachments
        FileExt = fso.GetExtensionName(att.FileName)
        AttachmentFullPath = SaveAttachmentPath & att.FileName
        'If found inner mail agian then check in that mail having any excel file ot not
        If UCase(FileExt) = "MSG" Then
            att.SaveAsFile AttachmentFullPath   'Save attachment
            DoEvents
            Call OpenMailNSaveXLS(AttachmentFullPath)   'Recursive call
            DoEvents
        ElseIf UCase(FileExt) = "XLS" Or UCase(FileExt) = "XLSX" Or UCase(FileExt) = "XLSM" Then   ' If it excel file then save it on same location.
            att.SaveAsFile SaveAttachmentPath & att.FileName    'Save attachment
            DoEvents
            OpenMailNSaveXLS = True
        ElseIf UCase(FileExt) = "TXT" Then    ' If it Text file then save it on same location.
            att.SaveAsFile SaveAttachmentPath & att.FileName    'Save attachment
            DoEvents
            OpenMailNSaveXLS = True
        Else
            'Ignore other than excel file
        End If
        DoEvents
    Next
    DoEvents
    MailItem.Close 1
    DoEvents
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)

Forum statistics

Threads
1,223,909
Messages
6,175,310
Members
452,634
Latest member
cpostell

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top