From 15e758d199e0d7305e9587cd609f494f9ad55285 Mon Sep 17 00:00:00 2001 From: Justin Luth Date: Mon, 6 Apr 2015 19:04:52 +0300 Subject: tdf#90447 vba end() needed to restore activesheet too. Change-Id: I650a5112511fd57099be3f0a84314d0577deae22 Reviewed-on: https://gerrit.libreoffice.org/15175 Tested-by: Jenkins Reviewed-by: Markus Mohrhard Tested-by: Markus Mohrhard --- sc/qa/extras/macros-test.cxx | 4 ++++ sc/qa/extras/testdocuments/vba_endFunction.xls | Bin 0 -> 2286592 bytes sc/source/ui/vba/vbarange.cxx | 15 ++++++++------- 3 files changed, 12 insertions(+), 7 deletions(-) create mode 100644 sc/qa/extras/testdocuments/vba_endFunction.xls diff --git a/sc/qa/extras/macros-test.cxx b/sc/qa/extras/macros-test.cxx index 2c6ac2b200a1..2c7f5b8da51e 100644 --- a/sc/qa/extras/macros-test.cxx +++ b/sc/qa/extras/macros-test.cxx @@ -225,6 +225,10 @@ void ScMacrosTest::testVba() OUString("Names."), OUString("vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") }, + { + OUString("vba_endFunction."), + OUString("vnd.sun.Star.script:VBAProject.testMacros.test?language=Basic&location=document") + }, }; OUString sTempDir; OUString sTempDirURL; diff --git a/sc/qa/extras/testdocuments/vba_endFunction.xls b/sc/qa/extras/testdocuments/vba_endFunction.xls new file mode 100644 index 000000000000..af7fa86256b5 Binary files /dev/null and b/sc/qa/extras/testdocuments/vba_endFunction.xls differ diff --git a/sc/source/ui/vba/vbarange.cxx b/sc/source/ui/vba/vbarange.cxx index 1e249a7e7d48..d312d3ae46e1 100644 --- a/sc/source/ui/vba/vbarange.cxx +++ b/sc/source/ui/vba/vbarange.cxx @@ -3557,17 +3557,18 @@ ScVbaRange::End( ::sal_Int32 Direction ) throw (uno::RuntimeException, std::exc // around ScTabView::MoveCursorArea(), thats the bit that calcutes // where the cursor should go ) // Main problem with this method is the ultra hacky attempt to preserve - // the ActiveCell, there should be no need to go to these extreems + // the ActiveCell, there should be no need to go to these extremes - // Save ActiveCell pos ( to restore later ) + // Save ActiveSheet/ActiveCell pos ( to restore later ) uno::Any aDft; uno::Reference< excel::XApplication > xApplication( Application(), uno::UNO_QUERY_THROW ); + uno::Reference< excel::XWorksheet > sActiveSheet = xApplication->getActiveSheet(); OUString sActiveCell = xApplication->getActiveCell()->Address(aDft, aDft, aDft, aDft, aDft ); // position current cell upper left of this range Cells( uno::makeAny( (sal_Int32) 1 ), uno::makeAny( (sal_Int32) 1 ) )->Select(); - uno::Reference< frame::XModel > xModel = getModelFromRange( mxRange ); + uno::Reference< frame::XModel > xModel = getModelFromRange( mxRange ); SfxViewFrame* pViewFrame = excel::getViewFrame( xModel ); if ( pViewFrame ) @@ -3607,14 +3608,14 @@ ScVbaRange::End( ::sal_Int32 Direction ) throw (uno::RuntimeException, std::exc // result is the ActiveCell OUString sMoved = xApplication->getActiveCell()->Address(aDft, aDft, aDft, aDft, aDft ); - // restore old ActiveCell uno::Any aVoid; + uno::Reference< excel::XRange > resultCell; + resultCell.set( xApplication->getActiveSheet()->Range( uno::makeAny( sMoved ), aVoid ), uno::UNO_QUERY_THROW ); - uno::Reference< excel::XRange > xOldActiveCell( xApplication->getActiveSheet()->Range( uno::makeAny( sActiveCell ), aVoid ), uno::UNO_QUERY_THROW ); + // restore old ActiveCell + uno::Reference< excel::XRange > xOldActiveCell( sActiveSheet->Range( uno::makeAny( sActiveCell ), aVoid ), uno::UNO_QUERY_THROW ); xOldActiveCell->Select(); - uno::Reference< excel::XRange > resultCell; - resultCell.set( xApplication->getActiveSheet()->Range( uno::makeAny( sMoved ), aVoid ), uno::UNO_QUERY_THROW ); // return result return resultCell; -- cgit