vba - how to save a file in a specific folder -
i have been working in code paste data vba file file. name of file paste data "endofdaydividends" , need save file everyday in same place , replace old one. save in desktop.
sub move_to_csvfile() dim x workbook dim y workbook dim strpath string dim filename string dim dd string set x = thisworkbook set y = workbooks.open("t:\ctg\edm\current edm ldn\macroeoddividend\endofdaydividends.csv") application.displayalerts = false x.sheets("code").range("a:f").entirecolumn.copy application.displayalerts = true application.displayalerts = false y.sheets("endofdaydividends").range("a1").pastespecial application.displayalerts = true x.close false activeworkbook.save end sub
with code, close macro file , leave opened "endofdaydividends" file. know how add command save on folder? need save in address t:\ctg\edm\current edm ldn\macroeoddividend\endofdaydividends.csv
can please try following?
code delete previous file, need add beginning of function before pasting new value:
setattr "t:\ctg\edm\current edm ldn\macroeoddividend\endofdaydividends.csv", vbnormal kill "t:\ctg\edm\current edm ldn\macroeoddividend\endofdaydividends.csv"
code save new file:
activeworkbook.saveas filename:="t:\ctg\edm\current edm ldn\macroeoddividend\endofdaydividends.csv", fileformat:=xlcsv, createbackup:=false
updated code: code should this. here, first delete existing csv file then, create new file , rename active sheet desire paste required values , save new created workbook new csv.
sub move_to_csvfile() dim x workbook dim y workbook dim strpath string dim filename string dim dd string set x = thisworkbook on error resume next setattr "t:\ctg\edm\current edm ldn\macroeoddividend\endofdaydividends.csv", vbnormal kill "t:\ctg\edm\current edm ldn\macroeoddividend\endofdaydividends.csv" on error goto 0 set y = workbooks.add y.activesheet.name = "endofdaydividends" application.displayalerts = false x.sheets("code").range("a:f").entirecolumn.copy application.displayalerts = true application.displayalerts = false y.sheets("endofdaydividends").range("a1").pastespecial application.displayalerts = true y.saveas filename:="t:\ctg\edm\current edm ldn\macroeoddividend\endofdaydividends.csv", fileformat:=xlcsv, createbackup:=false x.close false end sub
Comments
Post a Comment