excel vba - macro takes out subject details -
i have written macro. take out subject details each email , display in worksheet. code loops through emails , subjects, experiencing issues when trying display in csv or worksheet. in code have commented out displaying worksheet. both ways experiencing issues.
sub subdetails() dim ns outlook.namespace dim inbox mapifolder dim item object dim atmt attachment dim filename string dim integer dim myolapp outlook.application set myolapp = createobject("outlook.application") set ns = myolapp.getnamespace("mapi") set inbox = ns.folders("ua forms") ' getdefaultfolder(olfolderinbox) set inbox = inbox.folders("inbox") = 0 if inbox.items.count = 0 msgbox "there no messages in inbox", vbinformation, _ "nothing found" exit sub end if '''section experiecing problem''' each item in inbox.items 'dim my_filenumber integer 'dim logstr string icol = 1 irow = 3 ' my_filenumber = freefile 'logstr = item 'open "\\dfs52672.link2\my documents\exceltutorials\authors.csv" append #my_filenumber 'print #my_filenumber, logstr 'close #my_filenumber 'i = + 1 'msgbox "your record has been logged" 'cells(irow, icol).value = item columns(6).value = item = + 1 msgbox "i found" & & "attached files." next item getattachments_exit: set atmt = nothing set item = nothing set ns = nothing exit sub getattachment_err: msgbox "an error has occurred." _ & vbcrlf & "please note , report following information." _ & vbcrlf & "macro name: getattachments" _ & vbcrlf & "error number: " & err.number _ & vbcrlf & "error description: " & err.description _ , vbcritical, "error!" resume getattachments_exit end sub
to list in excel (col a) subject line of emails in inbox try changing loop this:
irow = 3 each item in inbox.items cells(irow, 1).value = item.subject irow = irow + 1 next item
this assuming have open workbook , references have been made. if not should add following:
dim wbnew workbook set wbnew = workbooks.add dim wksnew worksheet set wksnew = wbnew.worksheets("sheet1") irow = 3 each item in inbox.items wksnew.cells(irow, 1).value = item.subject irow = irow + 1 next item
Comments
Post a Comment