vba - csv output from excel error but other data types work correctly? -
ok attempting write macro saves excel workbook csv file. have tried many different solutions still having issues getting values print properly. when open file produces. rest of code left out takes original spreadsheet , copys contents temporary sheet can take multiple sheets same wb , print them same csv file. has module clear formatting , contents of temporary file. ran code print new excel spreadsheet , worked fine not print csv not sure why
out set looks this:
k ! bîh^ [content_types].xml ¢( [… skip bunch of binary lines …] kÆ8k¡~¥-ÙÔäá ûÜ my code looks this:
sub savefile() dim newname string dim nm name dim ws worksheet if msgbox("copy specific sheets new workbook" & vbcr & _ "new sheets pasted values, named ranges removed" _ , vbyesno, "newcopy") = vbno exit sub application .screenupdating = false ' re-create specific sheets ' *set sheet names re-create below* ' array("sheet name", "another sheet name", "and another")) ' sheet names go within quotes, seperated commas on error goto errcatcher sheets(array("raw info copy")).copy on error goto 0 ' paste sheets values ' remove external links, hperlinks , hard-code formulas ' create sure a1 selected on sheets each ws in activeworkbook.worksheets ws.cells.copy ws.[a1].pastespecial paste:=xlvalues ws.cells.hyperlinks.delete application.cutcopymode = false cells(1, 1).select ws.activate next ws cells(1, 1).select ' remove named ranges each nm in activeworkbook.names nm.delete next nm ' input box name new file newname = "test" ' save newname , in same directory original activeworkbook.savecopyas thisworkbook.path & "\" & newname & ".csv" activeworkbook.close savechanges:=false .screenupdating = true end exit sub errcatcher: msgbox "specified sheets not exist within workbook" end sub
savecopyas saves excel workbook in excel format. if append .csv filename, file still .xls formatted file.
the workbook saveas method lets specify type of file want save to.
however, if utilize saveas method, changes name of current file.
this before question on stack overflow has options on how utilize saveas method without changing name of file working on.
why vba activeworkbook.saveas alter open spreadsheet? has comments on how utilize saveas method , not have name of current file changed in process.
excel vba export-to-csv
No comments:
Post a Comment