outlook vba - Create CSV from array in VBA -
i'm novice programmer trying automate repetitive workplace tasks should done clever script instead of humans. i've done vba , java, basic stuff.
we have data generated validated online form gets emailed mailbox, , filter in mail client (outlook 2010) puts particular folder. intention write vba when triggered check contents of folder, , each mail item, message body text string, create array, , write array contents .csv file. i'll have app (imacros firefox) read csv , interact in-house corporate webapp rest.
i think can of except write array contents csv.
i work best looking @ code examples (i try understand ms object model documentation), best can find writing vba array csv like:
'save file open sfilename output #7 n = 0 ubound(myarray, 1) print #7, format(myarray(n, 0), "0.000000e+00") next n close #7
i think vb , not vba, general idea here valid? or if else has code sample me started or other pointers i'd grateful.
ps have seen how save 2-dimensional array csv file? can't understand it.
the code below works converting 2d arrays in csv. have not written code, have tested , works!
' saveascsv saves array csv file. choosing delimiter different comma, optional. ' ' syntax: ' saveascsv dmyarray, smyfilename, [smydelimiter] ' ' examples: ' saveascsv dchrom, app.path & "\demo.csv" --> comma delimiter ' saveascsv dchrom, app.path & "\demo.csv", ";" --> semicolon delimiter ' ' rev. 1.00 [8 jan 2003] ' written p. wester ' wester@kpd.nl public sub saveascsv(myarray() variant, sfilename string, optional sdelimiter string = ",") dim n long 'counter dim m long 'counter dim scsv string 'csv string print on error goto errhandler_saveascsv 'check extension , correct if needed if instr(sfilename, ".csv") = 0 sfilename = sfilename & ".csv" else while (len(sfilename) - instr(sfilename, ".csv")) > 3 sfilename = left(sfilename, len(sfilename) - 1) wend end if 'if multidimensional(myarray()) = false '1 dimension 'save file ' open sfilename output #7 ' n = 0 ubound(myarray(), 1) ' print #7, format(myarray(n, 0), "0.000000e+00") ' next n ' close #7 'else 'more dimensional 'save file open sfilename output #7 n = 1 ubound(myarray(), 1) scsv = "" m = 1 ubound(myarray(), 2) scsv = scsv & format(myarray(n, m)) & sdelimiter next m scsv = left(scsv, len(scsv) - 1) 'remove last delimiter print #7, scsv next n close #7 'end if exit sub errhandler_saveascsv: close #7
Comments
Post a Comment