-
1 Attachment(s)
Mmmm, strange. I tested it for me (off course) and it worked fine (with a different base path, no p:\group\data but just on my c drive).
If your email isn't located in the inbox it doesn't adapt the path to the folder inside your project but saves the mail in the found projectfolder.
So not in p:\group\jobdata\range_of_jobs\the_job\correspondence\email.in
but it will save to
p:\group\jobdata\range_of_jobs\the_job
What's the name of the file ?
Because if you look at the select case argument for knowing if it's inbox or sent folder, the sender or recipient get's added to the filename.
Is correspondence written like that ? In your directory structure ?
Full coding attached to import into a codemodule. I assume you know how to add a module inside outlook.
Remove the module with the coding for this little project and import this file into a module. Extract the zip and you get a bas file.
Charlize
-
I have found the issue, i was trying to save emails from a folder within the inbox in outlook and not the Main inbox, when i move the emails to the inbox it saves them no problem.
I have added the .bas file to outlook at it works for any inbox/sent item fine, i still get the message boxes with the range but ill take them out myself.
-
Only one or two msgbox 'es are still active :) unless I have missed some, my apologies than.
1. To let you know if a certain directory isn't according to the naming convention
2. To let you know the program has found your folder
3. If a project folder isn't found and the mail couldn't be saved.
Rest of messageboxes could be left out.
Anyway, hope you like this solution and mark this thread as solved.
Charlize
ps. seems you can click on a star to rate me :) . No obligation off course
-
My mistake! you have taken them out thanks!
This solution is great and thanks for your help!
I have one question,is it possible to change the code so it will see folders that are in the inbox?
Inbox Folder/13469-ABB Folder
-
This code will check the folder in which the mailitem is located. You could think about something to get that number as a proposed value at the inputbox where you give the projectnumber. It's doable.
Needs some thinking beforehand.
- Need to check before I give inputbox if mail is located in subfolder yes or no
- Then I can propose the projectid when the inputbox comes up
- Or only give inputbox when no number is found ?
Code:
Private Sub get_folder_of_email()'declare a mapifolder
Dim myfolder As MAPIFolder
'declare mailitem
Dim myitem As MailItem
'put an email in this variable
Set myitem = Outlook.ActiveExplorer.Selection.Item(1)
'get folder of the mailitem
Set myfolder = myitem.Parent
'check if folder of this mailitem is subfolder (one level higher)
'of inbox. so the parent folder of myfolder must be inboxfolder
If myfolder.Parent = Outlook.Session.GetDefaultFolder(olFolderInbox) Then
MsgBox "Mailmessage is stored in subfolder of Inbox." & _
"Foldersname = " & myfolder
Else
'no inboxfolder as folder one level higher or no inboxfolder
MsgBox "Mailmessage isn't stored in subfolder of inbox."
End If
End Sub
...
Charlize
-
It doesn't need to be that complicated, its only for when its saving the email, so it realises that the email is in a sub folder of the inbox.
-
A 'quick and dirty' solution for also saving into the project subfolders if you save an email that resides in a subfolder of the inbox ...
You need to replace the select case .... end case coding with the following code.
you have
Code:
'select if the selected mail is located in the inbox or sent items folder
Select Case objItem.Parent
Case Outlook.Session.GetDefaultFolder(olFolderInbox)
'change saving path accordingly
mypath = mypath & "Correspondence\Email.In\"
emailfrom = objItem.Sender
Case Outlook.Session.GetDefaultFolder(olFolderSentMail)
mypath = mypath & "Correspondence\Email.Out\"
emailto = objItem.To
End Select
must become
Code:
'select if the selected mail is located in the inbox or sent items folder
Select Case objItem.Parent
Case Outlook.Session.GetDefaultFolder(olFolderInbox)
'change saving path accordingly
mypath = mypath & "Correspondence\Email.In\"
emailfrom = objItem.Sender
Case Outlook.Session.GetDefaultFolder(olFolderSentMail)
mypath = mypath & "Correspondence\Email.Out\"
emailto = objItem.To
Case Else
mypath = mypath & "Correspondence\Email.In\"
emailfrom = objItem.Sender
End Select
Charlize
-
Charlize,
Thank you for your continued support and help!
that works a treat!
I have added rep!
Nathan