VBA Try and Catch (MS Outlook) -
i use following function monitor public outlook folder new e-mails arrive:
public sub application_startup() set newmail = application.getnamespace("mapi").folders(3).folders(2).... end sub
for reason, path public folder changes on time in weekly period. changes number in .folders(3)
. varies 1 3. apparently, keep function working , catch error, when path changes, want implement try , catch function such as:
try { set newmail = application.getnamespace("mapi").folders(1).folders(2).... catch error try { set newmail = application.getnamespace("mapi").folders(2).folders(2).... catch error try { set newmail = application.getnamespace("mapi").folders(2).folders(2).... catch error
since new vba struggeling implementing try , catch function. can assist vba code in outlook?
i think 1 solution manage implement is:
for = 1 3 on error resume next set newmail = application.getnamespace("mapi").folders(i).folders(2).... next
error handling in vba based on on error statement. following articles explains how handle errors in vba:
try/catch blocks add-ins.
note, can use namespace.getdefaultfolder method public folders folder in exchange public folders store. need pass olpublicfoldersallpublicfolders value. see sample code on following pages:
Comments
Post a Comment