i convert xlsx files in directory csv files. each resulting csv file should contain first worksheet of xlsx file , saved in subfolder of directory. using following script works fine, except saves worksheets separate csv. need first.
could tell me how modify script? have little experience vba.
sub loop_through_files() dim ws excel.worksheet dim mypath string dim myfile string dim myextension string dim fldrpicker filedialog application.screenupdating = false application.displayalerts = false myextension = "*.xl??" mypath = activeworkbook.path myfile = dir(mypath & "\" & "input" & "\" & myextension) 'loop through each excel file in folder while myfile <> "" 'open workbook set x = workbooks.open(filename:=mypath & "\" & "input" & "\" & myfile) savetodirectory = activeworkbook.path each ws in x.worksheets ws.saveas savetodirectory & left(x.name, instr(x.name, ".") - 1) & "_" & ws.name, xlcsv next x.close savechanges:=true 'get next file name myfile = dir loop application.screenupdating = true application.displayalerts = true end sub
replace for
loop this:
ws = x.sheets(1) ws.saveas savetodirectory & left(x.name, instr(x.name, ".") - 1) & "_" & ws.name, xlcsv
Comments
Post a Comment