vba - outlook 2013 incoming mail -
i've build vba-project checks inbox on special emails,
extracts attachement , save attachement on network.
happens when user clicks on button.
my problem want automate this.
therefore i've tried rewrite vba project but
when email arrives error message
'unzulässiger oder nicht ausreichend defnierter verweis'
(tr. improper or no sufficient defined reference)
i can't figure out , therefore i'm trying
answer here.
attached you'll find code placed in 'thisoutlooksession'
private withevents items outlook.items private sub application_startup() dim objns outlook.namespace dim x integer set objns = getnamespace("mapi") set items = objns.getdefaultfolder(olfolderinbox).items end sub private sub items_itemadd(byval item object) dim objns outlook.namespace dim strpath, strauditpath, strsavpath, strfoldername string dim oattachment outlook.attachment dim objtrash outlook.folder dim intanlagen, inttotal, integer set objns = getnamespace("mapi") on error goto check_error if typeof item outlook.mailitem dim msg outlook.mailitem set msg = item if msg.senderemailaddress = "notify@someone.com" if left(msg.subject, 8) = "qhst-log" strsavpath = "d:\users\as400_qhst_logs\" strpath = "t:\dokumente\as400\qhst-logs\" strauditpath = "d:\dropbox\qhst-log\" strfoldername = right(msg.subject, 4) if dir(strpath & strfoldername, vbdirectory) = vbnullstring 'prüfen ob subfolder der form jjjj angelegt ist. mkdir strpath & strfoldername mkdir strauditpath & strfoldername mkdir strsavpath & strfoldername end if strpath = strpath & strfoldername & "\" strauditpath = strauditpath & strfoldername & "\" strsavpath = strsavpath & strfoldername & "\" strfoldername = mid(.subject, 14, 2) if dir(strpath & strfoldername, vbdirectory) = vbnullstring mkdir strpath & strfoldername mkdir strauditpath & strfoldername mkdir strsavpath & strfoldername end if strpath = strpath & strfoldername & "\" strauditpath = strauditpath & strfoldername & "\" strsavpath = strsavpath & strfoldername & "\" intanlagen = msg.attachments.count inttotal = inttotal + intanlagen 'debug.print objnewmail & ": "; intanlagen if intanlagen > 0 = 1 intanlagen set oattachment = msg.attachments.item(i) oattachment.saveasfile strpath & oattachment.filename oattachment.saveasfile strauditpath & oattachment.filename next end if msg.unread = false msg.delete end if end if end if check_error: debug.print err.number; err.description if err.number = 75 err.clear goto back1: else err.raise err.number, err.description end if err.clear resume next end sub
try
set objns = application.getnamespace("mapi")
edit: reference application object
http://msdn.microsoft.com/en-us/library/office/ff865800%28v=office.15%29.aspx
syntax
expression .getnamespace(type)
expression variable represents application object.
Comments
Post a Comment