Tweak code to copy sheet1 of a excel file to sheet1 new excel file -
i have code copy sheets 1 excel file another, have 1 sheet , when copies paste original sheet1 (2) in destination file.
i need code not create new sheet past sheet1 sheet1 of destination file
i tryed playing not it
thanks
sub copysheets() dim wb workbook dim sourcewb workbook dim ws worksheet dim asheet worksheet 'turns off screenupdating , events: application.screenupdating = false application.enableevents = false 'sets variables: set wb = activeworkbook set asheet = activesheet set sourcewb = workbooks.open(wb.path & "\myotherworkbook.xls") 'modify match 'copies each sheet of sourcewb end of original wb: each ws in sourcewb.worksheets ws.copy after:=wb.sheets(wb.sheets.count) next ws sourcewb.close savechanges:=false set ws = nothing set sourcewb = nothing wb.activate asheet.select set asheet = nothing set wb = nothing application.enableevents = true end sub
try below code.the below code can fail if source workbook in excel 2010 (xlsx) , destination workbook in excel 2003 (xls). may have @ rdbmerge addin.
sub copysheets() dim sourcewb workbook, destinwb workbook dim sourcest worksheet dim filepath string 'turns off screenupdating , events: application.screenupdating = false application.displayalerts = false 'path refers limesurvey workbook set sourcewb = workbooks.open(thisworkbook.path & "\limesurvey.xls") 'set source sheet set sourcest = sourcewb.sheets("management suite feedback - tri") sourcest.copy set destinwb = activeworkbook filepath = createfolder destinwb.saveas filepath destinwb.close set destinwb = nothing set sourcest = nothing sourcewb.close set sourcewb = nothing application.screenupdating = true application.displayalerts = true end sub function createfolder() string dim fso object, myfolder string set fso = createobject("scripting.filesystemobject") myfolder = thisworkbook.path & "\reports" if fso.folderexists(myfolder) = false fso.createfolder (myfolder) end if myfolder = myfolder & "\" & format(now(), "mmm_yyyy") if fso.folderexists(myfolder) = false fso.createfolder (myfolder) end if createfolder = myfolder & "\data " & format(now(), "dd-mm-yy hh.mm.ss") & ".xls" set fso = nothing end function
Comments
Post a Comment