Open user specified Excel workbook and copy data range to another workbook -
i trying run macro in excel user chooses file open , macro copy range workbook , paste user specified cell in original workbook. attempt @ code shown below. have "wbthis" original workbook pasted , "wbtarget" workbook being opened , copied from. when run code, can choose file want open gives error saying "object required" , doesn't proceed further copying , pasting.
is there way use workbook.open instead of application.getopenfilename still have user able choose file open?
thank help.
dim wbtarget workbook dim wbthis workbook set wbthis = activeworkbook set wbtarget = application.getopenfilename(filefilter:="excel workbook (*.xls),*.xls", title:="open data") wbthis.activate set rdest = application.inputbox(prompt:="please select cell paste to", title:="paste to", type:=8) on error goto 0 wbtarget.activate application.cutcopymode = false wbtarget.range("a1").select wbtarget.range("b6:b121").copy wbthis.activate rdest.pastespecial (xlpastevalues) application.cutcopymode = false wbtarget.close false
getopenfilename not opens file, gets it's name. try doing application.workbooks.open(theresultofgetopenfilename)
dim filename string filename = application.getopenfilename(filefilter:="excel workbook (*.xls),*.xls", title:="open data") set wbtarget = application.workbooks.open(filename)
Comments
Post a Comment