-
.PST FILE SAVEAS IN A FOLDER AND SUBFOLDER
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
-
Yes it is possible, do you have any code written so far?
-
i have no idea!
sorry
can you help me?
-
Do you want to save emails automatically as they arrive, or is this something you want to do manually?
-
I JP, I want to save emails automatically. I write this loop
[VBA]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
[/VBA]
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
-
Provare questo:
[vba]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[/vba]
-
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
-
This code goes in the ThisOutlookSession module. See Where do I put my Outlook VBA code? for placement assistance.
-
Hi JP,
I try your snippet but does not work.
-
Did you restart Outlook after pasting in the code?
-
-
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.
-
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
-
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
-
Increased PST File Size
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:
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules