Commits

Anonymous committed a0047af

calc69: #i116936# fix VBA symbol Cells

  • Participants
  • Parent commits 054b0a0

Comments (0)

Files changed (3)

basic/source/classes/sbxmod.cxx

  
 void SbModule::SetVBACompat( sal_Bool bCompat )
 {
-	mbVBACompat = bCompat;
+    if( mbVBACompat != bCompat )
+    {
+        mbVBACompat = bCompat;
+        // initialize VBA document API
+        if( mbVBACompat ) try
+        {
+            StarBASIC* pBasic = static_cast< StarBASIC* >( GetParent() );
+            uno::Reference< lang::XMultiServiceFactory > xFactory( getDocumentModel( pBasic ), uno::UNO_QUERY_THROW );
+            xFactory->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ooo.vba.VBAGlobals" ) ) );
+        }
+        catch( Exception& )
+        {
+        }
+    }
 }
+
 // Ausfuehren eines BASIC-Unterprogramms
 sal_uInt16 SbModule::Run( SbMethod* pMeth )
 {

sc/source/ui/vba/vbaapplication.cxx

 uno::Reference< excel::XWorkbook >
 ScVbaApplication::getActiveWorkbook() throw (uno::RuntimeException)
 {
-    // will throw if active document is not in VBA compatibility mode (no object for codename)
-    return uno::Reference< excel::XWorkbook >( getVBADocument( getCurrentExcelDoc( mxContext ) ), uno::UNO_QUERY_THROW );
+	uno::Reference< frame::XModel > xModel( getCurrentExcelDoc( mxContext ), uno::UNO_SET_THROW );
+    uno::Reference< excel::XWorkbook > xWorkbook( getVBADocument( xModel ), uno::UNO_QUERY );
+    if( xWorkbook.is() ) return xWorkbook;
+    // #i116936# getVBADocument() may return null in documents without global VBA mode enabled
+    return new ScVbaWorkbook( this, mxContext, xModel );
 }
 
 uno::Reference< excel::XWorkbook > SAL_CALL 
 ScVbaApplication::getThisWorkbook() throw (uno::RuntimeException)
 {
-    // should never throw as this model is in VBA compatibility mode
-    return uno::Reference< excel::XWorkbook >( getVBADocument( getThisExcelDoc( mxContext ) ), uno::UNO_QUERY_THROW );
+	uno::Reference< frame::XModel > xModel( getThisExcelDoc( mxContext ), uno::UNO_SET_THROW );
+    uno::Reference< excel::XWorkbook > xWorkbook( getVBADocument( xModel ), uno::UNO_QUERY );
+    if( xWorkbook.is() ) return xWorkbook;
+    // #i116936# getVBADocument() may return null in documents without global VBA mode enabled
+    return new ScVbaWorkbook( this, mxContext, xModel );
 }
 
 uno::Reference< XAssistant > SAL_CALL
 	sal_Int32 nCursorX = pTabView->GetCurX();
 	sal_Int32 nCursorY = pTabView->GetCurY();
 
-    uno::Reference< XHelperInterface > xParent( excel::getUnoSheetModuleObj( xRange ), uno::UNO_QUERY_THROW );
-	return new ScVbaRange( xParent, mxContext, xRange->getCellRangeByPosition( nCursorX, nCursorY, nCursorX, nCursorY ) );
+    // #i117392# excel::getUnoSheetModuleObj() may return null in documents without global VBA mode enabled
+	return new ScVbaRange( excel::getUnoSheetModuleObj( xRange ), mxContext, xRange->getCellRangeByPosition( nCursorX, nCursorY, nCursorX, nCursorY ) );
 }
 
 uno::Any SAL_CALL

sc/source/ui/vba/vbaworkbook.cxx

 	uno::Reference< sheet::XSpreadsheetView > xView( xModel->getCurrentController(), uno::UNO_QUERY_THROW );
     uno::Reference< sheet::XSpreadsheet > xSheet( xView->getActiveSheet(), uno::UNO_SET_THROW );
     // #162503# return the original sheet module wrapper object, instead of a new instance
-    return uno::Reference< excel::XWorksheet >( excel::getUnoSheetModuleObj( xSheet ), uno::UNO_QUERY_THROW );
+    uno::Reference< excel::XWorksheet > xWorksheet( excel::getUnoSheetModuleObj( xSheet ), uno::UNO_QUERY );
+    if( xWorksheet.is() ) return xWorksheet;
+    // #i116936# excel::getUnoSheetModuleObj() may return null in documents without global VBA mode enabled
+    return new ScVbaWorksheet( this, mxContext, xSheet, xModel );
 }
 
 uno::Any SAL_CALL