How do I save ut8 encoding with excel vba macro -
i'm generating tsv file macro data contains special characters 'tm' symbol , in turn fed mysqlimport in server. because of special characters doesn't load rest of string after special character.
i have following macro save preffered delimiter , enclosure want specify encoding want save file in well. how go this?
sub tsv() dim srcrg range dim currrow range dim currcell range dim currtextstr string dim listsep string dim fname variant fname = application.getsaveasfilename("", "tsv file (*.tsv), *.tsv") 'fname = application.getsaveasfilename("", "csv file (*.csv), *.csv") 'assign character delimiter want listsep = chr(9) 'listsep = "|" 'assign enclosure character want listenc = "^" if selection.cells.count > 1 set srcrg = selection else set srcrg = activesheet.usedrange end if open fname output #1 each currrow in srcrg.rows currtextstr = "" each currcell in currrow.cells currtextstr = currtextstr & listenc & currcell.value & listenc & listsep next while right(currtextstr, 1) = listsep currtextstr = left(currtextstr, len(currtextstr) - 1) wend print #1, currtextstr next close #1 end sub
use adodb stream object.
set bs = createobject("adodb.stream") '2 = text use writetext rather 1 = binary , use write bs.type = 2 'get list of chartypes typing in command prompt ***reg query hkey_classes_root\mime\database\charset*** bs.charset = "utf-8" bs.open bs.writetext "hi kiddies" 'a=array(cbyte("m"),cbyte("z")) 'bs.write bs.savetofile "c:\myfile.txt", 2
Comments
Post a Comment