excel - VBA date double quotation mark gives triple quotation mark -
i have strange problem excel vba code. have date string column in csv spreadsheet wrap around in double quotation marks. wrote vba script in excel achieve this. however, everytime run script, date string output wrapped in 3 sets of double quotation marks instead of one.
i this:
"""2015-11-11 00:00:00.40""",59845,-0.20375,3.447,2.0135,32.08286,12,32,11.6
instead of this:
"2015-11-11 00:00:00.40",59845,-0.20375,3.447,2.0135,32.08286,12,32,11.6
where going wrong? have tried using char(34)
, chr(34)
represent "
has not helped. here script:
sub quotations() ' ' quotations macro ' ' dim strfile string strfile = dir("e:\copy\*.csv") ' create new workbook , assign variable dim wb workbook while len(strfile) > 0 set wb = workbooks.add windows("personal.xlsb").activate wb.activate activesheet.querytables.add(connection:= _ "text;e:\copy\" + strfile, destination:= _ range("$a$1")) .name = "e:\copy\" + strfile .fieldnames = true .rownumbers = false .filladjacentformulas = false .preserveformatting = true .refreshonfileopen = false .refreshstyle = xlinsertdeletecells .savepassword = false .savedata = true .adjustcolumnwidth = true .refreshperiod = 0 .textfilepromptonrefresh = false .textfileplatform = 850 .textfilestartrow = 1 .textfileparsetype = xldelimited .textfiletextqualifier = xltextqualifierdoublequote .textfileconsecutivedelimiter = false .textfiletabdelimiter = false .textfilesemicolondelimiter = false .textfilecommadelimiter = true .textfilespacedelimiter = false .textfilecolumndatatypes = array(2, 1, 1, 1, 1, 1, 1, 1, 1) .textfiletrailingminusnumbers = true .refresh backgroundquery:=false end range("j1").select activecell.formular1c1 = "=chr(34)&rc[-9]&chr(34)" range("j2").select columns("j:j").columnwidth = 23.57 range("j1").select selection.autofill destination:=range("j1:j864000") range("j1:j864000").select selection.copy columns("a:a").select selection.pastespecial paste:=xlpastevalues, operation:=xlnone, skipblanks _ :=false, transpose:=false columns("j:j").select application.cutcopymode = false selection.delete shift:=xltoleft 'activewindow.smallscroll down:=-6 activeworkbook.saveas filename:= _ "e:\copy\quotes\" + strfile, fileformat:= _ xlcsv, createbackup:=false activewindow.close savechanges:=false strfile = dir loop end sub
what doing wrong? in advance help.
from https://en.wikipedia.org/wiki/comma-separated_values
"fields containing line-break, double-quote, and/or commas should quoted"
when save modified file csv, excel sees quotes added , adds quotes around fields. when doubles-up quotes added escape them (so not interpreted field quotes program parsing saved file)
if re-open csv file in excel you'll see parsed correctly, , single set of quotes added displayed.
Comments
Post a Comment