Quantcast
Channel: VBForums - Visual Basic 6 and Earlier
Viewing all articles
Browse latest Browse all 21103

VBA - Save messages with configurated subject

$
0
0
Hi guys,

I am new on the forum and I hope you could help me. I don't have wide experience with VBA and most of things I have forgot, I am working mostly with Matlab nowadays :)
Since I am using outlook and I am receiving a lot of e-mails with information to perform some statistic analysis. What I need is to save a copy of that e-mails in my hard disk. My idea is that after receiving the e-mail and taking the information from there, I could change the subject manually, save the e-mail with that subject, asign it to category and create a rule for that category run a script. That script will be to save a copy to my disk.
To be more clear, the subject will look like this: xxxxx1_xxxxxx2_xxxxxxx3_20.03.2013 where the xxx are just names and locations, so the file name will be: xxxxx1_xxxxxx2_xxxxxxx3_20.03.2013.msg (containing its attachments). I need also to create the folders after formating the date like: data\2013\march\xxxxx1_xxxxxx2_xxxxxxx3_20.03.2013.msg.
I started a piece of code, see below.

Apparently I am doing something wrong because it is not working. I know it is just probably a basic thing, but could you help me out?
Thank you!

Public Sub SaveToDisk(itm As Outlook.MailItem)



Dim saveFolder As String
Dim basicpath As String
Dim month As String
Dim xxxxx1 As String
Dim xxxxxx2 As String
Dim xxxxxx3 As String
Dim Date_1 As String



Set Subject = itm.Subject

Dim avarSplit As Variant
avarSplit = Split(Range(Subject).Value, "_")

spliting = UBound(avarSplit)
xxxxx1= avarSplit(1)
xxxxxx2 = avarSplit(2)
xxxxxx3 = avarSplit(3)
Date_1 = avarSplit(4)


Dim datesplit As Variant
datesplit = Split(Range(Date_1).Value, ".")

month = datesplit(2)
Year = datesplit(3)

'-------------------------------
'let's see if the folder exists

basicpath = "C:\"
saveFolder = [basicpath, "\", Year, "\", month, "\order\", xxxxx1, " ", xxxxx2]


If Dir(saveFolder) = 0 Then
CreateFolder (saveFolder)
End

itm.SaveAsFile saveFolder


End Sub

Viewing all articles
Browse latest Browse all 21103

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>