jana
asked on
VBA to move selected email from an Inbox to X folder within same PST or another PST in Outlook
Hi!
I am trying to create a script that would send the selected email in either 2 PST Inbox and move them to specif project folder.
I have various PST files where each has an Inbox receiving emails.
I want to click on any email on any PST inbox and move them to their project folder.
The Projects folders are located under the Default PST Inbox:
PST File 1(All in inbox)
Inbox (256)
Projects DONE
Sivana LLC Project
Done tasks of Sivana
ToBeDeleted tasks of Sivana
Authorize First
Rurals Projects
Done tasks of Rurals
ToBeDeleted tasks of Rurals
Authorize First
PST FIles 2
Inbox (10)
Projects DONE
GNN LLC Project
Done tasks of GNN
ToBeDeleted tasks of GNN
Authorize First
Notice the in this example I have two inbox (2 PST) where the PST File 1 is the default PST. Also notices that both PST have up to each Inbox has 5 level of folders created under their respected Inbox.
What I am trying to do is at any Inbox click on the received email and send it to any folder of any PST.
I have search and worked on varios script, this is the closest I had found:
The problem seems to be in
Please help on the code
I am trying to create a script that would send the selected email in either 2 PST Inbox and move them to specif project folder.
I have various PST files where each has an Inbox receiving emails.
I want to click on any email on any PST inbox and move them to their project folder.
The Projects folders are located under the Default PST Inbox:
PST File 1(All in inbox)
Inbox (256)
Projects DONE
Sivana LLC Project
Done tasks of Sivana
ToBeDeleted tasks of Sivana
Authorize First
Rurals Projects
Done tasks of Rurals
ToBeDeleted tasks of Rurals
Authorize First
PST FIles 2
Inbox (10)
Projects DONE
GNN LLC Project
Done tasks of GNN
ToBeDeleted tasks of GNN
Authorize First
Notice the in this example I have two inbox (2 PST) where the PST File 1 is the default PST. Also notices that both PST have up to each Inbox has 5 level of folders created under their respected Inbox.
What I am trying to do is at any Inbox click on the received email and send it to any folder of any PST.
I have search and worked on varios script, this is the closest I had found:
Sub aaaMoveIboxToFolderDEST()
Dim OutApp As Outlook.Application
Dim oNS As Outlook.NameSpace
Dim objInboxFolder As Outlook.MAPIFolder
Dim objDestFolder As Outlook.MAPIFolder
Dim curFolder As Outlook.MAPIFolder
'Spring up PST/Folders
usrSubfolders.Show 'variable 'PST_FolderSelected'
Set OutApp = Application
Set oNS = OutApp.GetNamespace("MAPI")
'use the selected folder
Set curFolder = OutApp.ActiveExplorer.currentfolder
'Set Inbox
Set objInboxFolder = oNS.GetDefaultFolder(olFolderInbox)
'Set Destination folder
Set objDestFolder = objInboxFolder.Parent.Folders(PST_FolderSelected) 'folder name select in form above
'move to the folder
curFolder.MoveTo objDestFolder
End Sub
The problem seems to be in
Set objDestFolder = objInboxFolder.Parent.Folders(PST_FolderSelected) '
the error message is:Please help on the code
ASKER
yes and I even place the constant, for example "ToBeDeleted tasks of Sivana" same error... maybe has something to do being a sub folder?
What is the data type of PST_FolderSelected?
»bp
»bp
ASKER
Folder name, alphanumeric, string
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Ok will try
ASKER
Hi Bill... I tested and it doesn't give any errors, it goes thru ok.. I have also tested going to with all level, as if I wanted to move the email to that speciific level:
No error message!
However, at the line "curFolder.MoveTo objDestFolder" it doesn't do the move - and I am running the VBA with step-by-step F8 and the curFolder.MoveTo objDestFolder has the value of the folder I want to send it to.
Help
- Set objDestFolder = objInboxFolder.Folders("Pr
ojects DONE")
- Set objDestFolder = objInboxFolder.Folders("Pr
ojects DONE").Folders("Sivana LLC Project").
- Set objDestFolder = objInboxFolder.Folders("Pr
ojects DONE").Folders("Sivana LLC Project").Folders("Done tasks of Sivana")
- Set objDestFolder = objInboxFolder.Folders("Pr
ojects DONE").Folders("Sivana LLC Project").Folders("Done tasks of Sivana").Folders("ToBeDele ted tasks of Sivana")
No error message!
However, at the line "curFolder.MoveTo objDestFolder" it doesn't do the move - and I am running the VBA with step-by-step F8 and the curFolder.MoveTo objDestFolder has the value of the folder I want to send it to.
Help
ASKER
Hi, working with it, I found that the line in question moves a folder. I don't want that. I want to move the selected email in the inbox to the destination folder.
This is the latest a bit more organize code:
Please help on the command that determines which email I have clicked on prior running the script and the actual moving to the destination folder.
Thank u!
This is the latest a bit more organize code:
Sub aaaMoveIboxToFolderDEST()
Dim OutApp As Outlook.Application
Dim oNS As Outlook.NameSpace
Dim objInboxFolder As Outlook.MAPIFolder
Dim objDestFolder As Outlook.MAPIFolder
Dim curFolder As Outlook.MAPIFolder
Dim ParentFolder, ChildFolder1, ChildFolder2, ChildFolder3, ChildFolder4 As String
'This is the manual resuts of a UserForem which I will be use to ask these folders later on
ParentFolder = "Projects DONE"
ChildFolder1 = "Sivana LLC Project" 'cust & prosp
ChildFolder2 = "Done tasks of Sivana"
ChildFolder3 = "ToBeDeleted tasks of Sivana"
ChildFolder4 = "Authorize First"
'Start the process
Set OutApp = Application
Set oNS = OutApp.GetNamespace("MAPI")
'use the selected folder
Set curFolder = OutApp.ActiveExplorer.currentfolder
'Set Inbox
Set objInboxFolder = oNS.GetDefaultFolder(olFolderInbox)
'Set Destination folder
Set objDestFolder = objInboxFolder.Folders(ParentFolder) _
.Folders(ChildFolder1).Folders(ChildFolder2).Folders(ChildFolder3).Folders(ChildFolder4)
'Move to the folder:
'--- missing statement to move the current select email to be
'--- sent to folder selected above
xxx
End Sub
Please help on the command that determines which email I have clicked on prior running the script and the actual moving to the destination folder.
Thank u!
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi and thanx! I was just working with it also and came with this:
It does move the email to the destination folder, but can you check if its correctly written?
I will try you code
Dim obj As Object
Set obj = Application.ActiveWindow
If TypeOf obj Is Outlook.Inspector Then
Set obj = obj.currentItem
Else
Set obj = obj.Selection(1)
obj.Move objDestFolder
End If
(I place this code at the last part of the routine of the script I sent u last night, after "'Move to the folder:")It does move the email to the destination folder, but can you check if its correctly written?
I will try you code
Yes, that looks like similar logic just done a little bit differently. The code at the link I provided is a little cleaner and using a function is a bit more modular, but at a quick look I think what you have should get the same result. And really in both cases we should make sure that something was selected...
»bp
»bp
ASKER
Thanx!
I just embeded your code and I see the email selected is chosen, but how do I move it?
GetCurrentItem.Move objDestFolder?
I just embeded your code and I see the email selected is chosen, but how do I move it?
GetCurrentItem.Move objDestFolder?
ASKER
Just tried it, it seems to work... thank u very much!
(if GetCurrentItem.Move objDestFolder is incorrect, please let me know)
(if GetCurrentItem.Move objDestFolder is incorrect, please let me know)
Looks good, glad that helped.
»bp
»bp
»bp