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

Status
Not open for further replies.

CodeVar

Member
Outlook version
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
 
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.
 
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.
 
Yeah, if you can't get it working, I'll try it.
 
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
S Outlook 365 Help me create a Macro to make some received emails into tasks? Outlook VBA and Custom Forms 1
S HTML to Plain Text Macro - Help Outlook VBA and Custom Forms 1
N Help creating a VBA macro with conditional formatting to change the font color of all external emails to red Outlook VBA and Custom Forms 5
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
S Custom Contact card - need help creating one Outlook VBA and Custom Forms 1
D Lifelong Windows user - new to Mac - Help!!! Using Outlook 3
L Help: set flag for sent mail to check if received an answer Outlook VBA and Custom Forms 2
Nufc1980 Outlook "Please treat this as private label" auto added to some emails - Help. Using Outlook 3
I Help with Smart Folder + Query Builder on IMAP Using Outlook 0
S Outlook 2002- "Send" button has disappeared. Help please. Using Outlook 1
A Outlook 2019 Help with forwarding email without mentioning the previous email sender. Outlook VBA and Custom Forms 0
Witzker Outlook 2019 HELP to get Template Path in a Function Outlook VBA and Custom Forms 2
CWM550 Outlook 365 HELP! Calendar Craziness! Using Outlook 5
e_a_g_l_e_p_i Has nobody used Office 2021 enough to help me or have you given up on me.......lol Using Outlook 1
X Open Hyperlinks in an Outlook Email Message (Help with Diane's solution) Outlook VBA and Custom Forms 3
L Help connecting to hosted exchange server 2016 Using Outlook 0
B Seeking help with Outlook rule Using Outlook 2
D Need help with MS Authenticator Using Outlook 4
I Outlook for Mac 2019 using on desktop and laptop IMAP on both need help with folders Using Outlook 1
FryW Need help modifying a VBA script for in coming emails to auto set custom reminder time Outlook VBA and Custom Forms 0
S.Champ Please help? I've imported a random workcalendar I dont even know who's. Can I undo it? and then I need to re-sync the google one again. Its a mess:( Using Outlook 2
e_a_g_l_e_p_i Outlook 2010 Help setting up Gmail account in Outlook 2010 Using Outlook 3
Y Filter unread emails in a search folder vba help Outlook VBA and Custom Forms 0
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

Similar threads

Back
Top