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:
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