Copying external sheet to current workbook, Excel VBA -


i'm working on small project in need add sheets open workbook external database of worksheets in workbook. made form import sheet required in open (active) workbook. sheets copied remote (in other folder same computer) workbook. using following code due unknown reasons sheets not getting copied current workbook. urgent appreciated.

dim wb workbook dim activewb workbook dim filepath string dim ows      string set activewb = application.activeworkbook  filepath = "d:\general required docs\data.xlsm"  if optfirst.value = true    application.screenupdating = false    application.displayalerts = false    on error resume next    ows = cbomaterial.value    set wb = application.workbooks.open(filepath)    wb.worksheets(ows).copy          after:=application.activeworkbook.sheets(thisworkbook.sheets.count)    activewb.activate    wb.close false     application.screenupdating = true    application.displayalerts = true 

change

wb.worksheets(ows).copy          after:=application.activeworkbook.sheets(thisworkbook.sheets.count) 

to

wb.worksheets(ows).copy          after:=activewb.sheets(activewb.sheets.count) 

assuming ows index of worksheet want copy.


Comments

Popular posts from this blog

Change php variable from jquery value using ajax (same page) -

Pull out data related to my apps from Android Play Store and iOS App Store -

How can I fetch data from a web server in an android application? -