Sunday, 15 March 2015

VBA Outlook rule to Run Script is not completing -



VBA Outlook rule to Run Script is not completing -

i'm have problem macro/script doesn't run via email rule

i have outlook rule looks email subject move email subfolder runs script move email attachment folder on c drive , deletes original email subfolder

everything seem setup correctly, security ok, , macro runs macro outside rule it's rule doesn't run script, here script i'm using

sub get_soh_all(mymail mailitem) on error goto saveattachmentstofolder_err dim ns namespace dim inbox mapifolder dim subfolder mapifolder dim item object dim atmt attachment dim filename string dim integer dim varresponse vbmsgboxresult set ns = getnamespace("mapi") set inbox = ns.getdefaultfolder(olfolderinbox) set subfolder = inbox.folders("data dump") ' come in right subfolder name. = 0 if len(dir("c:\data dump\stock on hand", vbdirectory)) = 0 mkdir "c:\data dump\stock on hand" end if each item in subfolder.items each atmt in item.attachments if right(atmt.filename, 3) = "csv" filename = "c:\data dump\stock on hand\" atmt.saveasfile filename & "stock_on_hand_all.csv" item.delete = + 1 end if next atmt next item saveattachmentstofolder_exit: set atmt = nil set item = nil set ns = nil exit sub saveattachmentstofolder_err: msgbox "an unexpected error has occurred." _ & vbcrlf & "please note , study next info jarrod hall." _ & vbcrlf & "macro name: getattachmentssoh" _ & vbcrlf & "error number: " & err.number _ & vbcrlf & "error description: " & err.description _ , vbcritical, "error!" resume saveattachmentstofolder_exit end sub

the code in script used on 1 item not multiple.

the mail service deleted can drop part of rule moves mail service , seek this.

sub get_soh_all(mymail mailitem) on error goto saveattachmentstofolder_err dim atmt attachment dim filename string if len(dir("c:\data dump\stock on hand", vbdirectory)) = 0 mkdir "c:\data dump\stock on hand" end if each atmt in mymail.attachments if right(atmt.filename, 3) = "csv" filename = "c:\data dump\stock on hand\" atmt.saveasfile filename & "stock_on_hand_all.csv" mymail.delete end if next atmt saveattachmentstofolder_exit: set mymail = nil exit sub saveattachmentstofolder_err: msgbox "an unexpected error has occurred." _ & vbcrlf & "please note , study next info jarrod hall." _ & vbcrlf & "macro name: getattachmentssoh" _ & vbcrlf & "error number: " & err.number _ & vbcrlf & "error description: " & err.description _ , vbcritical, "error!" resume saveattachmentstofolder_exit end sub

vba outlook outlook-vba

No comments:

Post a Comment