Outlook Macro extract data to csv -


i want extract data email , save in csv. far convert excel, there code can add can save csv after finished running first macro.

option explicit  sub copytoexcel()     dim xlapp object     dim xlwb object     dim xlsheet object     dim olitem outlook.mailitem     dim vtext variant     dim stext string     dim vitem variant     dim long     dim rcount long     dim bxstarted boolean     const strpath string = "d:\my documents\vehicles.xlsx" 'the path of workbook      if application.activeexplorer.selection.count = 0         msgbox "no items selected!", vbcritical, "error"         exit sub     end if     on error resume next     set xlapp = getobject(, "excel.application")     if err <> 0         application.statusbar = "please wait while excel source opened ... "         set xlapp = createobject("excel.application")         bxstarted = true     end if     on error goto 0     'open workbook input data     set xlwb = xlapp.workbooks.open(strpath)     set xlsheet = xlwb.sheets("sheet1")      'process each selected record     each olitem in application.activeexplorer.selection         stext = olitem.body         vtext = split(stext, chr(13))         'find next empty line of worksheet         rcount = xlsheet.usedrange.rows.count         rcount = rcount + 1          'check each line of text in message body         = ubound(vtext) 0 step -1             if instr(1, vtext(i), "a card/order") > 0                 vitem = split(vtext(i), chr(58))                 xlsheet.range("d" & rcount) = trim(vitem(1))             end if              if instr(1, vtext(i), "required shipdate:") > 0                 vitem = split(vtext(i), chr(58))                 xlsheet.range("e" & rcount) = trim(vitem(1))             end if              if instr(1, vtext(i), "card quantity:") > 0                 vitem = split(vtext(i), chr(58))                 xlsheet.range("n" & rcount) = trim(vitem(1))             end if         next         xlsheet.rows(1).delete         xlsheet.range("a1").value = "0"         xlsheet.range("b1").value = "862"         xlsheet.range("c1").value = "00-100-6360"          xlsheet.range("f1").value = "0"         xlsheet.range("g1").value = "0"         xlsheet.range("h1").value = "0"         xlsheet.range("i1").value = "0"         xlsheet.range("j1").value = "0"         xlsheet.range("k1").value = "0"         xlsheet.range("l1").value = "0"         xlsheet.range("m1").value = "0"         xlsheet.range("o1").value = "0"         xlsheet.range("p1").value = "0"         xlsheet.range("q1").value = "0"         xlsheet.range("r1").value = "0"         xlsheet.range("s1").value = "0"         xlsheet.range("t1").value = "0"         xlsheet.range("u1").value = "0"         xlwb.save     next olitem      xlwb.close savechanges:=true     if bxstarted         xlapp.quit     end if     set xlapp = nothing     set xlwb = nothing     set xlsheet = nothing     set olitem = nothing end sub 

i tried:

 activeworkbook.saveas fileformat:=xlcsv  

but not save file csv .

reference: social msdn forums

before

xlwb.close savechanges:=true 

try

xlwb.saveas fileformat:=xlcsv 

or

xlwb.saveas fileformat:=6 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -