VBScript Move sent mail to non-default folder

Status
Not open for further replies.

Mark White

Member
Outlook version
Outlook 2013 64 bit
Email Account
Exchange Server
Hi,
I'm trying to move a sent email from the sent box to an other shared mailbox subfolder.

I can't use VBA as macros are disabled and am finding it difficult to change the GetFolderPath() function to work in VBScript.
Below is how I call it but I'm having trouble converting the VBA code into VBScript...

Does anyone have that functionality that allows traversing the folders that they could share with me?
Cheers
Mark

Dim sTarget, sSubject
Dim olApp, olNS, olMsg, olFldr

sTarget = WScript.Arguments(0)
sSubject = WScript.Arguments(1)

Set olFldr = GetFolderPath(sTarget) '****************

Set olApp = GetObject(,"Outlook.Application")
Set olNS = olApp.getNamespace("MAPI")
For each olMsg in olNS.getDefaultFolder(5).Items
If olMsg.Subject = sSubject Then
olMsg.move olFldr
End If
Next
Set olMsg = nothing
Set olNS = nothing
Set olApp = nothing

WScript.StdOut.WriteLine "Done"
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
This is working here - use "data file display name\folder\subfolder" for the target

Code:
Dim objFolder
Dim sTarget, sSubject, olApp, olNS, olMsg, olFldr, aFolders, fldr, i, objNS, strFolderPath
Set OutApp = GetObject(,"Outlook.Application")
Set objNS = OutApp.GetNamespace("MAPI")

sTarget = WScript.Arguments(0)
sSubject = WScript.Arguments(1)

Set objFolder =  GetFolder(sTarget)
For each olMsg in objNS.getDefaultFolder(5).Items
If olMsg.Subject = sSubject Then
olMsg.move objFolder
End If
Next
msgbox "Done"
Function GetFolder(FolderPath)
 'Dim objFolder

 ' folder path needs to be something like 
  '   "Public Folders\All Public Folders\Company\Sales"
  Dim aFolders
  Dim fldr
  Dim i
  Dim objNS

  On Error Resume Next
  strFolderPath = Replace(FolderPath, "/", "\")
  aFolders = Split(FolderPath, "\")

  'get the Outlook objects
  ' use intrinsic Application object in form script
 
Set OutApp = CreateObject("Outlook.Application") 
Set objNS = OutApp.GetNamespace("MAPI")

  'set the root folder
  Set fldr = objNS.Folders(aFolders(0))

  'loop through the array to get the subfolder
  'loop is skipped when there is only one element in the array
  For i = 1 To UBound(aFolders)
    Set fldr = fldr.Folders(aFolders(i))
    'check for errors
    If Err <> 0 Then Exit Function
  Next
  Set GetFolder = fldr

  ' dereference objects
  Set objNS = Nothing
End Function
 

Mark White

Member
Outlook version
Outlook 2013 64 bit
Email Account
Exchange Server
Thanks, Diane, I haven't been able to come back to this site for a couple of days, but I'll give this a go.

Will give you feedback as soon as poss but thanks again.
m
 

Mark White

Member
Outlook version
Outlook 2013 64 bit
Email Account
Exchange Server
Brilliant, Diane - works a treat. Thanks you so so much
Mark
 

Lina001

New Member
Outlook version
Outlook 2016 32 bit
Email Account
Exchange Server
I am happy that you find the way to solve your problem.
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
Mark White VBScript Move sent mail to non-default folder Outlook VBA and Custom Forms 0
B VBScript doesn't run on Recipient Email Outlook VBA and Custom Forms 2
M VbScript for Command Button on Contacts Custom Form Using Outlook 1
M Forward Appointment as BCC with VBScript Outlook VBA and Custom Forms 7
D Security patch seems to kill vbscript on Enterprise Level Outlook VBA and Custom Forms 4
R VBScript Commands Outlook VBA and Custom Forms 2
S my vbscript button1_click code works on appointment created but not on opening an existing apntmn Outlook VBA and Custom Forms 16
JorgeDario Template oft that contains VBScript Is not running Using Outlook 1
J Outlook 2010 VBScript editor does not run code at all Outlook VBA and Custom Forms 0
T Create new item in public folder using VBscript Outlook VBA and Custom Forms 1
R VBScript Sendmail not selecting correct 'from' address Outlook VBA and Custom Forms 3
B Recommended Outlook & VBScript Books? Outlook VBA and Custom Forms 3
Mary B VBscript: Need to copy every email to a folder & mark that copy as read Outlook VBA and Custom Forms 5
K VBScript Outlook, add attachment Outlook VBA and Custom Forms 1
S VBA Macro to VBScript Outlook VBA and Custom Forms 1
E VBScript to replace module? Using Outlook 3
F VBScript to add pre defined text Using Outlook 5
D Custom form and VBScript Using Outlook 5
F VBScript copy contacts and remove duplicates Using Outlook 1
R VBA Macro to VBScript in a form- Help Please! Using Outlook 10
H Accessing a control on a frame in Outlook with VBScript Outlook VBA and Custom Forms 1
Y Creating a Task with VBScript Outlook VBA and Custom Forms 14
N VBScript does not run in Outlook 2003 Outlook VBA and Custom Forms 4
GregS Outlook 2016 Move Outlook to new computer? Using Outlook 1
witzker Macro to move @domain.xx of a Spammail to Blacklist in Outlook 2019 Outlook VBA and Custom Forms 4
G Move tasks up/down todo list by VBA Outlook VBA and Custom Forms 1
S Macro to move “Re:” & “FWD:” email recieved the shared inbox to a subfolder in outlook Outlook VBA and Custom Forms 0
S Outlook Macro to move reply mail based on the key word in the subjectline Outlook VBA and Custom Forms 0
D Move Email with Attachment to Folder Outlook VBA and Custom Forms 3
Eike Move mails via macro triggered by the click of a button? Outlook VBA and Custom Forms 0
G Cannot Move Autocomplete File to New Computer Using Outlook 15
M Move to Folder Using Outlook 1
P Move emails between 2 mailboxes. Using Outlook 0
C Copy Move item won't work Outlook VBA and Custom Forms 2
N Macro to move all recipients to CC while replying Outlook VBA and Custom Forms 0
Commodore Move turns into "copy" Using Outlook 3
R List folders in a combo box + select folder + move emails from inbox to that folder + reply to that email Outlook VBA and Custom Forms 1
Jennifer Murphy Ctrl+Tab sometimes will not move through text a word at a time Using Outlook 1
V Outlook 2016 will not move emails in search results Using Outlook 4
M move to iCloud not working in outlook calendar Using Outlook 12
A Create date folder and move messages daily Outlook VBA and Custom Forms 1
Commodore Folders always closed in move/copy items dialog box Using Outlook 3
C Move Outlook 2007 to new PC with Outlook 365 Using Outlook 3
C Can't move folder, the folder is full Using Outlook 0
Nadine Rule to move attachments with specific name Outlook VBA and Custom Forms 1
A Move email items based on a list of email addresses Outlook VBA and Custom Forms 40
T Move calendar invites to new calendar Using Outlook 5
O Rule to move (specific) messages from Sent folder to Specific folder Using Outlook 1
I Automating message move between folders Outlook VBA and Custom Forms 0
K Outlook Rules: Move a Copy Using Outlook 4

Similar threads

Top