PDA

View Full Version : .PST FILE SAVEAS IN A FOLDER AND SUBFOLDER



garko75
05-30-2012, 02:48 AM
HY GUYS, THIS IS MY SITUATION ..

RECEIVE A LOT OF MAIL. THE OBJECT IS EQUAL TO A PART OF STRING.

ES.SUBJECT: HR>SURNAME

THE LAST NAME IS THE VARIABLE PORTION OF THE SUBJECT.

I WANT TO SAVE A COPY (WITH ATTACHEMENT) OF MAIL RECEIVED IN A SUB-FOLDER THAT IS CALLED AS THE LAST NAME (VARIABLE POTION OF THE SUBJECT OF MAILS).

IS IT POSSIBLE ...

THANKS FOR YOUR HELP:bug:

JP2112
05-30-2012, 08:43 AM
Yes it is possible, do you have any code written so far?

garko75
05-30-2012, 09:07 AM
i have no idea!
sorry
can you help me?

JP2112
06-01-2012, 01:22 PM
Do you want to save emails automatically as they arrive, or is this something you want to do manually?

garko75
06-04-2012, 02:11 AM
I JP, I want to save emails automatically. I write this loop
Sub SALVAMAIL()

Dim appOl As New Outlook.Application
Dim ns As Outlook.NameSpace
Dim inBox As Outlook.MAPIFolder
Dim SubFolder As Outlook.MAPIFolder
Dim Item As Object
Dim MSGITEM As MailItem
Dim MSGNAME As String
Dim MSGPATH As String
Dim MSGSUBJECT As String
Dim I As Long

Set ns = appOl.GetNamespace("MAPI")
Set inBox = ns.GetDefaultFolder(olFolderInbox)
Set SubFolder = inBox.Folders("PROVA")

I = 1

If SubFolder.Items.Count = 0 Then
MsgBox "Non ci sono mail da esportare", vbInformation, "ESPORTAZIONE"
Exit Sub
End If

For I = 1 To SubFolder.Items.Count
Set MSGITEM = SubFolder.Items(I)

MSGSUBJECT = MSGITEM.Subject
MSGNAME = MSGITEM.Subject
MSGPATH = "C:\Documents and Settings\XXX\Documenti\ATTA\" & MSGNAME & ".MSG"
MSGITEM.SaveAs MSGPATH
MSGITEM.UnRead = False

Next I

Set Item = Nothing
Set ns = Nothing
Set appOl = Nothing
Set MAILITEMS = Nothing

End Sub

I want to create a new folder (in subfolder ATTA) , in hd, with the same name as the object message.
thank for your help, excuse me for my bad english.
Have a nice day
G75

JP2112
06-04-2012, 07:59 AM
Provare questo:

Private WithEvents Items As Outlook.Items

Private Sub Application_Startup()
Dim olApp As Outlook.Application
Dim objNS As Outlook.NameSpace
Set olApp = Outlook.Application
Set objNS = olApp.GetNamespace("MAPI")
Set Items = objNS.GetDefaultFolder(olFolderInbox).Items
End Sub

Private Sub Items_ItemAdd(ByVal item As Object)

On Error Goto ErrorHandler

Dim Msg As Outlook.MailItem
Dim surname As String
Dim folderName As String

Const BASE_PATH As String = "C:\Documents and Settings\XXX\Documenti\ATTA\"

If TypeName(item) = "MailItem" Then
Set Msg = item
' ottenere il nome
surname = Split(Msg.Subject,">")(1)

' verificare se cartella esiste
folderName = BASE_PATH & surname
If Len(Dir(folderName)) = 0 Then ' creare la cartella
MkDir folderName
End If

Msg.SaveAs folderName & "\" & Msg.Subject & ".msg", olMSG

End If

ProgramExit:
Exit Sub
ErrorHandler:
MsgBox Err.Number & " - " & Err.Description
Resume ProgramExit
End Sub

garko75
06-04-2012, 03:52 PM
Hi JP, excuse me but where I put your loop? must I add this in the standard module of ol?
you can explane to me as if I had 5 years
sorry..sorry

JP2112
06-05-2012, 06:06 AM
This code goes in the ThisOutlookSession module. See Where do I put my Outlook VBA code? (http://www.jpsoftwaretech.com/outlook-vba/where-do-i-put-my-outlook-vba-code/) for placement assistance.

garko75
06-05-2012, 02:44 PM
Hi JP,
I try your snippet but does not work.

JP2112
06-06-2012, 09:31 AM
Did you restart Outlook after pasting in the code?

garko75
06-06-2012, 08:35 PM
Yes but don't work.

JP2112
06-07-2012, 12:01 PM
Welcome to the forum. If you want help, I need you to meet me halfway on this. I'm afraid I don't have the patience to play Twenty Questions today.

"don't work" is simply not enough for me or anyone else to assist you.

May I kindly suggest you set a breakpoint in the code and drop a relevant email into your Inbox, then step through the code to see what happens? You'll need to do some debugging yourself to find out what went wrong.

garko75
06-08-2012, 04:54 AM
SORRY BUT I WAS WRONG TO PUT YOUR CODE. YOUR LOOP FUNCTION PERFECTLY BUT DON'T SAVE .MSG FILE IN THE CREATED FOLDER, I TRY TO MAKE SOME CHANGES, IF I CAN NOT, I TRY - AGAIN - TO ASK YOUR HELP. WHEN I WAS ANSWERED "DON'TWORK" IN ITALY WERE 3 OF THE MORNING AND I HAD NOT SLEPT ALL NIGHT, ALSO, I HAD ANSWERED WITH THE IPAD AND I COULD NOT TESTING THE CODE.
OTHERWISE THANKS FOR YOUR HELP.
CIAO

garko75
06-14-2012, 12:50 AM
Hi JP
are you sure that the cycle start only when a new message arrives in a specific subfolder (of Outlook) through a rule?
Thanks and regards

cooperj105
08-13-2012, 11:40 PM
If you are facing trouble due to increase in pst file then don't worry. You can split pst file using pst2gb.exe which is an inbuilt tool and split the pst file quite easily. Just search this tool on your machine and split the outlook in multiple chunks. Apart from this there is also another option available in the form of third party PST splitter tool. So you have both the option either use inbuilt free tool or take help of third party tool to split the pst file and optimize its performance. For more information you can visit: