vb.net - Copy worksheet to another workbook VB in different excel instance -
i need copy worksheet 1 workbook workbook in different excel instance. got error ('exception hresult: 0x800a03ec) @ "inputsht.copy(after:=chartsheet)" line when using below code, can tell me wrong please.(excelwb defined public var.)
private sub chartinexcelbtn_click(sender object, e routedeventargs) handles chartinexcelbtn.click dim excelwb excel.workbook dim inputsht worksheet dim chartfile excel.application = new microsoft.office.interop.excel.application() dim chartworkbook excel.workbook dim chartsheet excel.worksheet excelwb = system.runtime.interopservices.marshal.bindtomoniker(xlfile) inputsht = excelwb.worksheets("input") chartworkbook = chartfile.workbooks.add chartsheet = chartworkbook.worksheets.add 'inputsht.copy(after:=chartworkbook.worksheets("sheet1")) inputsht.copy(after:=chartsheet) chartfile.visible = true end sub
i found answer in below link: copy worksheet 1 instance of excel another
so change code below , working:
private sub chartinexcelbtn_click(sender object, e routedeventargs) handles chartinexcelbtn.click dim excelwb excel.workbook dim inputsht worksheet dim chartfile excel.application = new microsoft.office.interop.excel.application() excelwb = system.runtime.interopservices.marshal.bindtomoniker(xlfile) inputsht = excelwb.worksheets("input") inputsht.copy(type.missing, type.missing) excelapp.displayalerts = false excelapp.workbooks(2).saveas("c:\test.xlsx") chartfile.workbooks.open("c:\test.xlsx", notify:=false, readonly:=true) chartfile.visible = true excelapp.workbooks(2).close(savechanges:=false) end sub
Comments
Post a Comment