Help with a Macro to move emails to a different PST data file

Status
Not open for further replies.

CodeVar

Member
Outlook version
Outlook 2007
Email Account
POP3
I was hoping someone could help me understand how to move emails to a different PST file. Currently I have edited a script I found online which allows emails to be moved to various folders based on a macro which executes either from a button in the top menu bar area, or with shortcut keys. Right now it is all working excellent, but I want to take it a step further and have it function the same but also allow a button which will move emails to a separate PST file. This particular macro will be running in Outlook 2007.

I read this but I wasn't able to get it functioning based on the macro I have customized:

http://www.slipstick.com/developer/macro-move-aged-mail/

My current Macro is as follows:

-It allows emails to be moved to 3 different folder locations within the main PST "Inbox" folder.

MACRO:

----------------------------------- 'Outlook VB Macro to move selected mail item(s) to a target folder

Sub MoveToFolder(targetFolder)

On Error Resume Next

Dim ns As Outlook.NameSpace

Dim MoveToFolder As Outlook.MAPIFolder

Dim objItem As Outlook.MailItem

Set ns = Application.GetNamespace("MAPI")

'define path to the target folder; the following assumes the target folder

'is a sub-folder of the main Mailbox folder

'This is the original'

'Set MoveToFolder = ns.Folders("Mailbox").Folders(targetFolder)'

Set MoveToFolder = ns.GetDefaultFolder(olFolderInbox).Folders(targetFolder)

If Application.ActiveExplorer.Selection.Count = 0 Then

MsgBox ("No item selected")

Exit Sub

End If

If MoveToFolder Is Nothing Then

MsgBox "Target folder not found!", vbOKOnly + vbExclamation, "Move Macro Error"

End If

For Each objItem In Application.ActiveExplorer.Selection

If MoveToFolder.DefaultItemType = olMailItem Then

If objItem.Class = olMail Then

objItem.Move MoveToFolder

End If

End If

Next

Set objItem = Nothing

Set MoveToFolder = Nothing

Set ns = Nothing

End Sub

Sub MoveToActive()

MoveToFolder ("Active")

End Sub

Sub MoveToAction()

MoveToFolder ("Action")

End Sub

Sub MoveToOnHold()

MoveToFolder ("OnHold")

End Sub

-----------------------------------Can someone help me configure it so a 4th option will move an email to a folder within a different PST?

For example I would like to add an extra button called "Archive", and when this particular button is clicked it will move the email to the archive folder within the separate PST's Inbox

Sub MoveToArchive()

MoveToFolder ("Archive")

End Sub
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
You need to get the folder path function - http://www.slipstick.com/developer/working-vba-nondefault-outlook-folders/




then call the path like this:




Set MoveToFolder = GetFolderPath(targetF older)




and call it using



MoveToFolder ("datafile-name-in-folderlist\Inbox\subfoldername")








I think it will work with the default folders too, so you could use one macro and the full path to the file in GetFolderPath - or you can use two macros, your orginial and one that uses the getfolderpath function.
 

CodeVar

Member
Outlook version
Outlook 2007
Email Account
POP3
You need to get the folder path function - http://www.slipstick.com/developer/working-vba-nondefault-outlook-folders/

then call the path like this:

Set MoveToFolder = GetFolderPath(targetF older)

and call it using
MoveToFolder ("datafile-name-in-folderlist\Inbox\subfoldername")

I think it will work with the default folders too, so you could use one macro and the full path to the file in GetFolderPath - or you can use two macros, your orginial and one that uses the getfolderpath function.

I want to start by saying Thank You, this was helpful in understanding the code further, but I'm still not able to get it to function. I tried to make a bunch of edits and possible adjustments but I don't know VBA well enough to make it work after all.

I'm going to try a bunch of different scenario's and will post back if I get it or not. If not, would you be able to possibly tweak the entire body of code so I can copy/paste it if I share the exact structure? I'll let you know how I make out on my own for now.
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
Yeah, if you can't get it working, I'll try it.
 

CodeVar

Member
Outlook version
Outlook 2007
Email Account
POP3
Yeah, if you can't get it working, I'll try it.

So I tried a bunch of combinations, but with no success. First using the original scrip, as well as the authors earlier version but couldn't get it to work as hoped with this extra functionality.

I am using this as a base with minor edits for my needs and to move emails to folders within the main data pst inbox folder (Look at the code which is stated as being updated 5/25/2011 which is more compact, but unsure if may be causing issues when trying to amend this new function):

http://jmerrell.com/2011/05/21/outlook-macros-move-email/

My goal is to keep this functioning as is, but then also add the ability to move an email to a separate pst archive folder. This new button I am looking to create will move an email to the secondary Archive PST in folder 1, or folder 2, both of which reside within the archive Inbox folder. I run both of these pst's in the same profile. My current example structure is a follows:

Main PST

Inbox

-Folder 1

-Folder 2

Secondary PST/Archive

Inbox

-Folder 1

-Folder 2

Any extra help you can share will be appreciated :)
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
R Help Revising VBA macro to delete email over different time span Outlook VBA and Custom Forms 0
J Help Please!!! Outlook 2016 - VBA Macro for replying with attachment in meeting invite Outlook VBA and Custom Forms 9
S VBA Macro - Run-time error '424': object required - Help Please Outlook VBA and Custom Forms 3
C Newbie needs help with Outlook Macro Outlook VBA and Custom Forms 3
A newb outlook macro help Outlook VBA and Custom Forms 1
E Help with macro to answer and delete calendar requests? Outlook VBA and Custom Forms 5
A Help creating macro for conditional formatting settings Using Outlook 8
S Help macro Outlook VBA and Custom Forms 1
F Help with Outlook 2007 Macro Please! Using Outlook 4
R VBA Macro to VBScript in a form- Help Please! Using Outlook 10
S Outlook macro help Using Outlook 10
P Please Help me Create a Macro ! Using Outlook 2
D Help with simple macro - looping though all emails in my inbox Using Outlook 3
S Macro help Using Outlook 4
S Outlook 2003: Help with setting up a macro to reply to selected emails Using Outlook 2
M Help - VB Macro no longer work Outlook VBA and Custom Forms 5
S MAcro - Need help in getting the recipients in to filed / cc field toput in an array Outlook VBA and Custom Forms 4
L Help for writing an Outlook 2007 macro Outlook VBA and Custom Forms 7
V Outlook macro help please Outlook VBA and Custom Forms 23
L Need help modifying a VBA script for emails stuck in Outbox Outlook VBA and Custom Forms 6
F Microsoft Outlook Connector 14.0.6123.5001 - Help! Using Outlook 6
witzker Pls help to change the code for inserting date in Ol contact body Outlook VBA and Custom Forms 5
R Disable conversation thread from replying of recipients in the same subject. Please help Using Outlook 0
R seperate read layout to design in outlook 2016..Help!! Outlook VBA and Custom Forms 3
O Help .. got lost ... installing Office like 2016 Using Outlook 5
A Arthur needs help with 2007 Outlook e-mail Using Outlook.com accounts in Outlook 3
Marc2019 Need help please! Cannot Setup my outlook email account on my Mac Outlook 2011 Using Outlook.com accounts in Outlook 2
L Attachment saving and tracking - PLEASE help! Outlook VBA and Custom Forms 5
I Help with dates in task list. Using Outlook 5
C need help setting up outlook first time Using Outlook 1
K To do bar help Using Outlook 8
M Help sending email but removing signature via VBA Outlook VBA and Custom Forms 5
S help with outlook scripting Outlook VBA and Custom Forms 4
EmelineGueguen Help to understand the problem of work Using Outlook 1
N Outlook Forms Help Outlook VBA and Custom Forms 2
N Need help syncing contacts to iPhone X Using Outlook 8
broadbander Needing help with reply/reply all while keeping attachments and adding a new CC recipient. Outlook VBA and Custom Forms 5
J Help! My contacts have disappeared. Using Outlook 5
J HELP- Rule to auto strip prepend from external emails Using Outlook 0
J Help Needed With Multi-Step Login Email Address Using Outlook.com accounts in Outlook 1
G Bcc help - Preventing multiple forwards from a bcc'd distribution group Using Outlook 1
G [Help] Converting array to destination folder path Outlook VBA and Custom Forms 1
K Help.... Office Outlook 2016 Using Outlook 1
S Error using AddressEntry.GetContact - need help Outlook VBA and Custom Forms 2
D Help with code to move mail on receipt to another folder based on time received Outlook VBA and Custom Forms 2
EaglePI Outlook 2010 need help with rules Using Outlook 0
B HELP! Using Outlook 4
Jeff Davis Help fix my Outlook 2013? Using Outlook 28
M Winmail. dat - HELP Using Outlook 2
Diane Poremsky Help! My Contacts are being updated! New Slipstick.com Articles 0

Similar threads

Top