Excel 2016 VBA activeworkbook actions are not done on activeworkbook once we change to thisworkbook -
i'm trying copy data workbook macro code written new workbook , renaming sheet. code works fine in 2013 same code throws error in windows 10 2016.
below sample code (made changes) sub test() range("a" & rows.count).end(xlup).offset(1, 0) = "this workbook" application.screenupdating = false set newwb = workbooks.add worksheets.add worksheets.add = 0 50 newwb.activate range("a" & rows.count).end(xlup).offset(1, 0) = "activeworkbook workbook" activeworkbook.sheets(1).name = "test" newwb.activate '--> don't need add code check if works , still same issue. activeworkbook.sheets(2).name = "test2" activeworkbook.sheets(3).name = "test3" thisworkbook.activate range("a" & rows.count).end(xlup).offset(1, 0) = "this workbook" next end sub can why throwing error? code works fine in windows 7 excel 2013 same code throws error in 2016. great if can me issue.
use direct referencing , avoid activeworkbook. should dim variables before use them...
sub test() on error goto exitsub application.screenupdating = false dim newwb workbook: set newwb = workbooks.add newwb.worksheets.add newwb.worksheets.add dim long thisworkbook.range("a" & rows.count).end(xlup).offset(1, 0) = "this workbook" newwb = 0 50 .range("a" & rows.count).end(xlup).offset(1, 0) = "activeworkbook workbook" .sheets(1).name = "test" .sheets(2).name = "test2" .sheets(3).name = "test3" thisworkbook.range("a" & rows.count).end(xlup).offset(1, 0) = "this workbook" next end exitsub: application.screenupdating = true end sub
Comments
Post a Comment