Move files to folder

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello all.

I would like som help in programming Outlook 2000.
What I want it to do, is to check mails on arrival.
If the subject contains a specific word, it will move the attached txt-file
to a folder on the desktop.
Is this possible?
I am new to Outlook programming.
I have some experience in programming Access, but not Outlook.
I assume the language is not the same, hehe.

BR
Claes
 
Hi Claes,

it´s almost ready. Just add a few lines in the Items_ItemAdd event
procedure for checking the subject. For that you can use the InStr
function.

In addition i you really want to move (not only copy) the attachments
then remove them from the mail after saving to the filesystem (with
oAtt.Delete). In this case, after changing the mail, you have to save
the mail item.


<DieseOutlookSitzung>
Private WithEvents Items As Outlook.Items

Private Sub Application_Startup()
Set Items = Application.Session.GetDefaultFolder(olFolderInbox).Items
End Sub

Private Sub Items_ItemAdd(ByVal Item As Object)
If TypeOf Item Is Outlook.MailItem Then
' check for the subject here
SaveAttachments Item
End If
End Sub

Public Sub SaveAttachments(oMail As Outlook.MailItem)
On Error Resume Next
Dim oAtt As Outlook.Attachment
Dim sPath As String
Dim sName As String

sPath = "c:\xyz\"
sPath = sPath & Format(oMail.ReceivedTime, "yyyymmdd_hhnnss_",
vbMonday, vbFirstJan1)

For Each oAtt In oMail.Attachments
sName = oAtt.FileName
ReplaceCharsForFileName sName, "_"
oAtt.SaveAsFile sPath & sName
Next
End Sub

' Ersetzt in Dateinamen unerlaubte Zeichen
Private Sub ReplaceCharsForFileName(sName As String, sChr As String)
sName = Replace(sName, "/", sChr)
sName = Replace(sName, "\", sChr)
sName = Replace(sName, ":", sChr)
sName = Replace(sName, "?", sChr)
sName = Replace(sName, Chr(34), sChr)
sName = Replace(sName, "<", sChr)
sName = Replace(sName, ">", sChr)
sName = Replace(sName, "|", sChr)
End Sub
</DieseOutlookSitzung>
 
Hello.

Thank you for the code.
I cant get it to work, hehe.
I have tried but I think I need some help with the inStr part to search for
the subject.
I am in a citrix environment.
Do you think that is a problem?

Thank you
/Claes

"Michael Bauer" skrev:
 
Citrix might be a problem if you don't have write permissions to write to
that folder. You can always read the registry at
HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders\Local
AppData to see where your local data should be stored under Citrix. In
general it would usually be at C:\Documents and Settings\<windows profile
name>\Application Data\.
 
Hi Claes,

I don´t know anything about citrix. So thanks for Ken´s jumping in.

If you need help for the InStr function so write it in your code, set
the cursor into the word, and press F1 for the (very good) VBA help,
please.
 
Back
Top