excel - Copy and paste to a closed workbook -
my question possible copy , paste closed workbook , save csv? first workbook active though suppose copying (from closed workbook) , pasting (to closed workbook) ideal not essential.
i'm sorry if silly question wondering save cpu unnecessary hardship , having open many excels.
the code below tends work enough though stumped how achieve pasting specific csv saving required active.
that being said can copy closed workbook active 1 though require opposite.
any appreciated :).
option explicit sub copytoarchive() dim wb1 excel.workbook set wb1 = workbooks.open("c:\users\excel.xlsx") dim wb2 excel.workbook set wb2 = workbooks.open("c:\users\csv.csv") wb1.sheets("sheet1").range("a1:z10000").copy wb2.sheets("sheet1").range("a65536").end(xlup).offset(1, 0).pastespecial _ paste:=xlpastevalues, operation:=xlnone, skipblanks:=false, transpose:=false wb1.close savechanges:=true end sub
you need open file in order write it. however, in specific case, because .csv file delimited text file, can write without opening in excel. don't know if faster, can try it. this:
option explicit sub copytoarchive() dim wb1 excel.workbook set wb1 = workbooks.open("c:\users\excel.xlsx") '//set variables delimiting workbook contents dim row range dim col long dim srowcontents string '//open file append open "c:\users\csv.csv" append #1 '//work through each row, , create comma delimited set of contents each row in wb1.sheets("sheet1").range("a1:z10000").rows col = 1 row.columns.count srowcontents = srowcontents & row.cells(1, col).value & "," next col print #1, srowcontents '//<= delimted line gets added. srowcontents = "" '//clear value next row. next row close #1 wb1.close savechanges:=true end sub
Comments
Post a Comment