This is an automated email from the ASF dual-hosted git repository.

asf-gitbox-commits pushed a commit to branch symphony-vba
in repository https://gitbox.apache.org/repos/asf/openoffice.git

commit 967ab3af24b97aaf6ca52c90d768e1e2b9d3e8f9
Author: Pedro Giffuni <[email protected]>
AuthorDate: Sun Oct 25 22:55:11 2026 -0500

    Implement OpenSolver v2.9.2 VBA compilation blockers
    
    Add #If conditional compilation support to BASIC compiler 
(PP_IF/ELSEIF/ELSE/ENDIF
    tokens + parser directives at module and procedure scope).
    
    Add VBA Interface keyword support (INTERFACE token + keyword mapping + 
parser
    handling treating Interface modules as CLASS type).
    
    Implement Scripting.Dictionary service (XDictionary.idl + ScVbaDictionary)
    and Scripting.FileSystemObject service (XFileSystemObject.idl +
    ScVbaFileSystemObject), both wired via CreateObject dispatch in sb.cxx.
    
    Add Application.ScreenUpdating and Application.Iteration properties to
    XApplication.idl and implement in ScVbaApplication with shared settings.
    
    Add Range.Value2 (getValue2/setValue2) and Range.Precedents/Dependents
    to XRange.idl and implement in ScVbaRange.
    
    Add Application.EnableCancelKey and Application.CalculationState with
    xlErrorHandler/xlDone enum constants.
    
    Fix XInterface.idl comment syntax, vbafiledialog.hxx duplicate member,
    helperdecl.hxx duplicate guards, vbarange.cxx missing method 
implementations,
    ambiguous base errors, and Library_vbaobj.mk source list.
---
 main/basic/source/classes/sb.cxx             |  15 +-
 main/basic/source/comp/parser.cxx            | 481 +++++++++++++++++++++++++--
 main/basic/source/comp/token.cxx             |  36 +-
 main/basic/source/inc/parser.hxx             |  16 +
 main/basic/source/inc/token.hxx              |   2 +
 main/oovbaapi/UnoApi_oovbaapi.mk             |   5 +
 main/oovbaapi/ooo/vba/XDictionary.idl        |  51 +++
 main/oovbaapi/ooo/vba/XFile.idl              |  56 ++++
 main/oovbaapi/ooo/vba/XFileSystemObject.idl  |  79 +++++
 main/oovbaapi/ooo/vba/XFolder.idl            |  59 ++++
 main/oovbaapi/ooo/vba/XTextStream.idl        |  67 ++++
 main/oovbaapi/ooo/vba/excel/XApplication.idl |   6 +-
 main/oovbaapi/ooo/vba/excel/XRange.idl       |   3 +
 main/sc/Library_vbaobj.mk                    |   2 +
 main/sc/source/ui/vba/helperdecl.hxx         |   3 -
 main/sc/source/ui/vba/service.cxx            |  14 +-
 main/sc/source/ui/vba/vbaapplication.cxx     |  53 ++-
 main/sc/source/ui/vba/vbaapplication.hxx     |  20 +-
 main/sc/source/ui/vba/vbadictionary.cxx      | 191 +++++++++++
 main/sc/source/ui/vba/vbadictionary.hxx      |  72 ++++
 main/sc/source/ui/vba/vbafiledialog.hxx      |   1 -
 main/sc/source/ui/vba/vbafilesystem.cxx      | 320 ++++++++++++++++++
 main/sc/source/ui/vba/vbafilesystem.hxx      |  89 +++++
 main/sc/source/ui/vba/vbarange.cxx           | 315 +++++++++++++++++-
 main/sc/source/ui/vba/vbarange.hxx           |  14 +
 main/sc/util/vbaobj.component                |   6 +
 main/udkapi/com/sun/star/uno/XInterface.idl  |   2 +-
 27 files changed, 1936 insertions(+), 42 deletions(-)

diff --git a/main/basic/source/classes/sb.cxx b/main/basic/source/classes/sb.cxx
index 11350c1f88..470c9a58de 100644
--- a/main/basic/source/classes/sb.cxx
+++ b/main/basic/source/classes/sb.cxx
@@ -436,7 +436,7 @@ SbxObject* SbiFactory::CreateObject( const String& rClass )
                String aCollectionName( 
RTL_CONSTASCII_USTRINGPARAM("Collection") );
                return new BasicCollection( aCollectionName );
        }
-       else
+    else
     if( rClass.EqualsIgnoreCaseAscii( "FileSystemObject" ) )
     {
         try
@@ -449,6 +449,19 @@ SbxObject* SbiFactory::CreateObject( const String& rClass )
         catch( Exception& )
         {}
     }
+    else
+    if( rClass.EqualsIgnoreCaseAscii( "Scripting.Dictionary" ) )
+    {
+        try
+        {
+            Reference< XMultiServiceFactory > xFactory( 
comphelper::getProcessServiceFactory(), UNO_SET_THROW );
+            ::rtl::OUString aServiceName( RTL_CONSTASCII_USTRINGPARAM( 
"ooo.vba.Scripting.Dictionary" ) );
+            Reference< XInterface > xInterface( xFactory->createInstance( 
aServiceName ), UNO_SET_THROW );
+            return new SbUnoObject( aServiceName, uno::makeAny( xInterface ) );
+        }
+        catch( Exception& )
+        {}
+    }
 
     return NULL;
 }
diff --git a/main/basic/source/comp/parser.cxx 
b/main/basic/source/comp/parser.cxx
index 5dfd4ce475..bec2748625 100644
--- a/main/basic/source/comp/parser.cxx
+++ b/main/basic/source/comp/parser.cxx
@@ -32,6 +32,12 @@ struct SbiParseStack {                               // 
"Stack" für Statement-Blocks
        sal_uInt32  nChain;                                     // JUMP-Chain
 };
 
+struct SbiPPFrame {                            // #i162175: Preprocessor #If 
stack frame
+       SbiPPFrame* pNext;                      // Chain
+       sal_Bool  bActive;                              // Current branch is 
active (being parsed)
+       sal_Bool  bAnyActive;                           // Any branch in this 
#If has been active
+};
+
 struct SbiStatement {
        SbiToken eTok;
        void( SbiParser::*Func )();             // Verarbeitungsroutine
@@ -116,19 +122,21 @@ static SbiStatement StmntTable [] = {
 #endif
 
 SbiParser::SbiParser( StarBASIC* pb, SbModule* pm )
-               : SbiTokenizer( pm->GetSource32(), pb ),
-                 aGblStrings( this ),
-                 aLclStrings( this ),
-                 aGlobals( aGblStrings, SbGLOBAL ),
-                 aPublics( aGblStrings, SbPUBLIC ),
-                 aRtlSyms( aGblStrings, SbRTL ),
-                 aGen( *pm, this, 1024 )
-{
-       pBasic   = pb;
-       eCurExpr = SbSYMBOL;
-       eEndTok  = NIL;
-       pProc    = NULL;
-       pStack   = NULL;
+               : SbiTokenizer( pm->GetSource32(), pb ),
+                 aGblStrings( this ),
+                 aLclStrings( this ),
+                 aGlobals( aGblStrings, SbGLOBAL ),
+                 aPublics( aGblStrings, SbPUBLIC ),
+                 aRtlSyms( aGblStrings, SbRTL ),
+                 aPreprocConstants( aGblStrings, SbGLOBAL ),
+                 aGen( *pm, this, 1024 )
+{
+       pBasic   = pb;
+       eCurExpr = SbSYMBOL;
+       eEndTok  = NIL;
+       pProc    = NULL;
+       pStack   = NULL;
+       pPPStack = NULL;  // #i162175: Preprocessor stack
        pWithVar = NULL;
        nBase    = 0;
        bText    =
@@ -150,11 +158,14 @@ SbiParser::SbiParser( StarBASIC* pb, SbModule* pm )
 
        rTypeArray = new SbxArray; // Array fuer Benutzerdefinierte Typen
        rEnumArray = new SbxArray; // Array for Enum types
-       bVBASupportOn = pm->IsVBACompat();
-       if ( bVBASupportOn )
-               EnableCompatibility();
+       bVBASupportOn = pm->IsVBACompat();
+       if ( bVBASupportOn )
+               EnableCompatibility();
 
-}
+       // #i162175: Set up preprocessor constants for #If conditional 
compilation
+       AddPreprocConstants();
+
+ }
 
 
 // Ist Teil der Runtime-Library?
@@ -389,6 +400,39 @@ sal_Bool SbiParser::Parse()
                Next(); return sal_True;
        }
 
+       // #i162175: Handle preprocessor directives (#If, #Const, #ElseIf, 
#Else, #End If)
+       if( eCurTok == PP_IF )
+       {
+               Next();
+               PP_If();
+               return sal_True;
+       }
+       if( eCurTok == PP_CONST )
+       {
+               Next();
+               PP_Const();
+               return sal_True;
+       }
+       // PP_ELSE/PP_ELSEIF/PP_ENDIF must be handled even in inactive branches
+       if( eCurTok == PP_ELSE || eCurTok == PP_ELSEIF || eCurTok == PP_ENDIF )
+       {
+               SbiToken ePPIfTok = eCurTok;  // Save before Next() changes 
eCurTok
+               Next();
+               if( ePPIfTok == PP_ELSE )
+                       PP_Else();
+               else if( ePPIfTok == PP_ELSEIF )
+                       PP_ElseIf();
+               else
+                       PP_EndIf();
+               return sal_True;
+       }
+       // #i162175: Skip inactive preprocessor branches
+       if( pPPStack && !pPPStack->bActive )
+       {
+               PP_SkipToNextBranch();
+               return sal_True;
+       }
+
        // Kommt ein Symbol, ist es entweder eine Variable( LET )
        // oder eine SUB-Prozedur( CALL ohne Klammern )
        // DOT für Zuweisungen im WITH-Block: .A=5
@@ -797,6 +841,10 @@ void SbiParser::Option()
                        bClassModule = sal_True;
                        aGen.GetModule().SetModuleType( 
com::sun::star::script::ModuleType::CLASS );
                        break;
+               case INTERFACE:
+                       bClassModule = sal_True;
+                       aGen.GetModule().SetModuleType( 
com::sun::star::script::ModuleType::CLASS );
+                       break;
                case VBASUPPORT:
                        if( Next() == NUMBER )
                        {
@@ -858,9 +906,402 @@ void SbiParser::AddConstants( void )
 
 void SbiParser::ErrorStmnt()
 {
-       SbiExpression aPar( this );
-       aPar.Gen();
-       aGen.Gen( _ERROR );
+       SbiExpression aPar( this );
+       aPar.Gen();
+       aGen.Gen( _ERROR );
 }
 
+// #i162175: Conditional compilation preprocessor support
+
+void SbiParser::AddPreprocConstants()
+{
+       // Platform constants for compile-time #If evaluation
+       SbiConstDef* pConst;
+
+       // Mac/W32/W64: false on non-Windows/Mac platforms
+ #if defined(UNX) || defined(__linux__)
+       pConst = new SbiConstDef( String::CreateFromAscii( "Mac" ) );
+       pConst->SetType( SbxBOOL );
+       pConst->Set( (double)0, SbxBOOL );
+       aPreprocConstants.Add( pConst );
+
+       pConst = new SbiConstDef( String::CreateFromAscii( "Win32" ) );
+       pConst->SetType( SbxBOOL );
+       pConst->Set( (double)0, SbxBOOL );
+       aPreprocConstants.Add( pConst );
+
+       pConst = new SbiConstDef( String::CreateFromAscii( "Win64" ) );
+       pConst->SetType( SbxBOOL );
+       pConst->Set( (double)0, SbxBOOL );
+       aPreprocConstants.Add( pConst );
+ #endif
+
+       // VBA7 is true (AOO VBA compatibility mode supports VBA7 features)
+       pConst = new SbiConstDef( String::CreateFromAscii( "VBA7" ) );
+       pConst->SetType( SbxBOOL );
+       pConst->Set( (double)-1, SbxBOOL );  // -1 = True in VBA
+       aPreprocConstants.Add( pConst );
+
+       // True = -1, False = 0 (VBA boolean conventions)
+       pConst = new SbiConstDef( String::CreateFromAscii( "True" ) );
+       pConst->SetType( SbxBOOL );
+       pConst->Set( (double)-1, SbxBOOL );
+       aPreprocConstants.Add( pConst );
+
+       pConst = new SbiConstDef( String::CreateFromAscii( "False" ) );
+       pConst->SetType( SbxBOOL );
+       pConst->Set( (double)0, SbxBOOL );
+       aPreprocConstants.Add( pConst );
+
+       // MAC_OFFICE_VERSION defaults to 0 on non-Mac platforms
+       pConst = new SbiConstDef( String::CreateFromAscii( "MAC_OFFICE_VERSION" 
) );
+       pConst->SetType( SbxDOUBLE );
+       pConst->Set( 0.0, SbxDOUBLE );
+       aPreprocConstants.Add( pConst );
+ }
+
+// #i162175: Evaluate a preprocessor constant by name
+// Returns the value (0 for false/undefined, -1 for true)
+static bool PP_GetConstantValue( SbiSymPool& rPool, const String& rName, 
double& rValue )
+{
+       SbiSymDef* pDef = rPool.Find( rName );
+       if( !pDef )
+               return false;
+       SbiConstDef* pConst = pDef->GetConstDef();
+       if( !pConst )
+               return false;
+       rValue = pConst->GetValue();
+       return true;
+}
+
+// #i162175: Simple compile-time expression evaluator for #If conditions
+// Grammar: expr := or_expr (Or or_expr)*
+bool SbiParser::PP_EvalOrExpr()
+{
+       bool bResult = PP_EvalAndExpr();
+       while( !bAbort )
+       {
+               Peek();
+               if( eCurTok == OR )
+               {
+                       Next();
+                       bool bRight = PP_EvalAndExpr();
+                       bResult = bResult || bRight;
+               }
+               else
+                       break;
+       }
+       return bResult;
+}
+
+// and_expr := not_expr (And not_expr)*
+bool SbiParser::PP_EvalAndExpr()
+{
+       bool bResult = PP_EvalNotExpr();
+       while( !bAbort )
+       {
+               Peek();
+               if( eCurTok == AND )
+               {
+                       Next();
+                       bool bRight = PP_EvalNotExpr();
+                       bResult = bResult && bRight;
+               }
+               else
+                       break;
+       }
+       return bResult;
+}
+
+// not_expr := Not not_expr | comparison
+bool SbiParser::PP_EvalNotExpr()
+{
+       Peek();
+       if( eCurTok == NOT )
+       {
+               Next();
+               return !PP_EvalNotExpr();
+       }
+       return PP_EvalComparison();
+}
+
+// comparison := term (comparison_op term)?
+bool SbiParser::PP_EvalComparison()
+{
+       double nLeft = PP_EvalTerm();
+       Peek();
+
+       if( eCurTok == EQ || eCurTok == NE || eCurTok == LT || eCurTok == GT ||
+               eCurTok == LE || eCurTok == GE )
+       {
+               SbiToken eOp = eCurTok;
+               Next();  // consume operator
+               double nRight = PP_EvalTerm();
+
+               switch( eOp )
+               {
+                       case EQ: return nLeft == nRight;
+                       case NE: return nLeft != nRight;
+                       case LT: return nLeft < nRight;
+                       case GT: return nLeft > nRight;
+                       case LE: return nLeft <= nRight;
+                       case GE: return nLeft >= nRight;
+               }
+       }
+       // No comparison operator - treat as boolean: non-zero = True
+       return (nLeft != 0);
+}
+
+// term := NUMBER | SYMBOL | True | False | ( expr )
+double SbiParser::PP_EvalTerm()
+{
+       Peek();
+
+       if( eCurTok == NUMBER )
+       {
+               double nVal = GetDbl();
+               Next();  // consume number
+               return nVal;
+       }
+       else if( eCurTok == SYMBOL )
+       {
+               String aName = aSym;
+               Next();  // consume symbol
+               double nVal = 0;
+               if( PP_GetConstantValue( aPreprocConstants, aName, nVal ) )
+                       return nVal;
+               // Unknown constant - treat as 0 (false)
+               // #i162175: Do not silently treat unknown constants as true
+               return 0;
+       }
+       else if( eCurTok == LPAREN )
+       {
+               Next();  // consume (
+               bool bResult = PP_EvalOrExpr();
+               Peek();
+               if( eCurTok == RPAREN )
+                       Next();  // consume )
+               else
+                       Error( SbERR_BAD_BRACKETS );
+               return bResult ? -1.0 : 0.0;  // True = -1, False = 0
+       }
+       else
+       {
+               Error( SbERR_UNEXPECTED, eCurTok );
+               Next();
+               return 0;
+       }
+}
+
+// #i162175: Evaluate preprocessor condition expression
+// Reads tokens until THEN or EOLN, evaluates expression
+bool SbiParser::PP_EvalCondition()
+{
+       bool bResult = PP_EvalOrExpr();
+
+       // Expect THEN (optional in some VBA dialects, but OpenSolver always 
uses it)
+       Peek();
+       if( eCurTok == THEN )
+               Next();  // consume THEN
+
+       return bResult;
+}
+
+// #i162175: Skip tokens in an inactive preprocessor branch
+// until reaching PP_ELSE, PP_ELSEIF, or PP_ENDIF at the same nesting level
+void SbiParser::PP_SkipToNextBranch()
+{
+       int nPPNesting = 0;
+
+       while( !IsEof() && !bAbort )
+       {
+               Peek();
+
+               // Consume empty lines and comments without processing
+               if( IsEoln( eCurTok ) )
+               {
+                       Next();
+                       continue;
+               }
+
+               if( eCurTok == REM )
+               {
+                       Next();
+                       continue;
+               }
+
+               if( eCurTok == PP_IF )
+               {
+                       nPPNesting++;
+                       Next();  // consume PP_IF, skip its condition
+                       // Skip condition expression until THEN or EOLN
+                       while( !IsEof() && !IsEoln( Peek() ) && Peek() != THEN )
+                               Next();
+                       if( Peek() == THEN )
+                               Next();  // consume THEN
+                       continue;
+               }
+
+               if( eCurTok == PP_ENDIF )
+               {
+                       if( nPPNesting > 0 )
+                       {
+                               nPPNesting--;
+                               Next();  // consume PP_ENDIF
+                               continue;
+                       }
+                       // Found matching #End If - leave it for Parse() to 
handle
+                       return;
+               }
+
+               if( nPPNesting == 0 && ( eCurTok == PP_ELSE || eCurTok == 
PP_ELSEIF ) )
+               {
+                       // Found #Else or #ElseIf at same level - leave it for 
Parse() to handle
+                       return;
+               }
+
+               // Skip this token
+               Next();
+       }
+ }
+
+// #i162175: #If expression Then ... #ElseIf ... #Else ... #End If
+void SbiParser::PP_If()
+{
+       bool bCondResult = PP_EvalCondition();
+
+       // Push preprocessor frame
+       SbiPPFrame* pFrame = new SbiPPFrame;
+       pFrame->pNext = pPPStack;
+       pFrame->bActive = bCondResult;     // This branch is active?
+       pFrame->bAnyActive = bCondResult;  // Has any branch been active?
+       pPPStack = pFrame;
+
+       if( !bCondResult )
+       {
+               // Skip inactive branch
+               PP_SkipToNextBranch();
+       }
+ }
+
+// #i162175: #ElseIf expression Then
+void SbiParser::PP_ElseIf()
+{
+       if( !pPPStack )
+       {
+               Error( SbERR_NO_IF );  // "Else without If"
+               return;
+       }
+
+       SbiPPFrame* pFrame = pPPStack;
+
+       if( pFrame->bAnyActive )
+       {
+               // A previous branch was already active - skip this branch
+               pFrame->bActive = false;
+               PP_SkipToNextBranch();
+       }
+       else
+       {
+               // Evaluate this ElseIf condition
+               bool bCondResult = PP_EvalCondition();
+               pFrame->bActive = bCondResult;
+               pFrame->bAnyActive = bCondResult;
+
+               if( !bCondResult )
+                       PP_SkipToNextBranch();
+       }
+ }
+
+// #i162175: #Else
+void SbiParser::PP_Else()
+{
+       if( !pPPStack )
+       {
+               Error( SbERR_NO_IF );  // "Else without If"
+               return;
+       }
+
+       SbiPPFrame* pFrame = pPPStack;
+       // Activate this branch only if no previous branch was active
+       pFrame->bActive = !pFrame->bAnyActive;
+ }
+
+// #i162175: #End If
+void SbiParser::PP_EndIf()
+{
+       if( !pPPStack )
+       {
+               Error( SbERR_NO_IF );  // "End If without If"
+               return;
+       }
+
+       SbiPPFrame* pFrame = pPPStack;
+       pPPStack = pFrame->pNext;
+       delete pFrame;
+ }
+
+// #i162175: #Const name = value
+void SbiParser::PP_Const()
+{
+       // Read constant name
+       if( !TestSymbol() )
+               return;
+
+       String aConstName = aSym;
+       sal_Bool bPrivate = sal_False;
+
+       // Check for Private/Public
+       Peek();
+       if( eCurTok == PRIVATE )
+       {
+               bPrivate = sal_True;
+               Next();
+               if( !TestSymbol() )
+                       return;
+               aConstName = aSym;
+       }
+       else if( eCurTok == PUBLIC )
+       {
+               Next();
+               if( !TestSymbol() )
+                       return;
+               aConstName = aSym;
+       }
+
+       // Expect '='
+       TestToken( EQ );
+
+       // Read value
+       Peek();
+       if( eCurTok == NUMBER )
+       {
+               double nVal = GetDbl();
+               Next();  // consume number
+               SbiConstDef* pConst = new SbiConstDef( aConstName );
+               pConst->SetType( SbxBOOL );
+               pConst->Set( nVal, SbxBOOL );
+               aPreprocConstants.Add( pConst );
+       }
+       else if( eCurTok == SYMBOL )
+       {
+               String aValName = aSym;
+               Next();  // consume symbol
+
+               double nVal = 0;
+               PP_GetConstantValue( aPreprocConstants, aValName, nVal );
+
+               // Check for True/False keywords
+               if( aValName.EqualsIgnoreCaseAscii( "True" ) )
+                       nVal = -1.0;
+               else if( aValName.EqualsIgnoreCaseAscii( "False" ) )
+                       nVal = 0.0;
+
+               SbiConstDef* pConst = new SbiConstDef( aConstName );
+               pConst->SetType( SbxVARIANT );
+               pConst->Set( nVal, SbxVARIANT );
+               aPreprocConstants.Add( pConst );
+       }
+ }
+
 /* vim: set noet sw=4 ts=4: */
diff --git a/main/basic/source/comp/token.cxx b/main/basic/source/comp/token.cxx
index 3959127f64..7808bf8214 100644
--- a/main/basic/source/comp/token.cxx
+++ b/main/basic/source/comp/token.cxx
@@ -64,6 +64,7 @@ static TokenTable aTokTable_Basic [] = {              // 
Token-Tabelle:
        { CASE,         "Case" },
        { _CDECL_,      "Cdecl" },
        { CLASSMODULE, "ClassModule" },
+       { INTERFACE,    "Interface" },
        { CLOSE,        "Close" },
        { COMPARE,      "Compare" },
        { COMPATIBLE,"Compatible" },
@@ -184,6 +185,12 @@ static TokenTable aTokTable_Basic [] = {           // 
Token-Tabelle:
        { WITHEVENTS,   "WithEvents" },
        { WRITE,        "Write" },                              // auch WRITE #
        { XOR,          "Xor" },
+       { VBASUPPORT,   "VbaSupport" },
+       { PP_IF,                "#If" },
+       { PP_ELSEIF,    "#ElseIf" },
+       { PP_ELSE,              "#Else" },
+       { PP_ENDIF,             "#End If" },
+       { PP_CONST,             "#Const" },
        { NIL,          "" }
 };
 
@@ -360,7 +367,7 @@ TokenLabelInfo::TokenLabelInfo( void )
        // Token accepted as label by VBA
        SbiToken eLabelToken[] = { ACCESS, ALIAS, APPEND, BASE, BINARY, 
CLASSMODULE,
                COMPARE, COMPATIBLE, DEFERR, _ERROR_, BASIC_EXPLICIT, LIB, 
LINE, LPRINT, NAME,
-               TOBJECT, OUTPUT, PROPERTY, RANDOM, READ, STEP, STOP, TEXT, 
VBASUPPORT, NIL };
+               INTERFACE, OPEN, PRINT, SET, STEP, STOP, TEXT, TYPE, 
VBASUPPORT, NIL };
        SbiToken* pTok = eLabelToken;
        SbiToken eTok;
        for( pTok = eLabelToken ; (eTok = *pTok) != NIL ; ++pTok )
@@ -571,6 +578,7 @@ special:
        {
                // AB, 15.3.96, Spezialbehandlung fuer END, beim Peek() geht die
                // aktuelle Zeile verloren, daher alles merken und danach 
restaurieren
+               sal_Bool bSavedHash = bHash;  // #i162175: preserve '#' prefix
                sal_uInt16 nOldLine = nLine;
                sal_uInt16 nOldCol  = nCol;
                sal_uInt16 nOldCol1 = nCol1;
@@ -601,7 +609,17 @@ special:
                        nCol2 = nOldCol2;
                        aSym = aOldSym;
                        RestoreLine();          // pLine im Scanner restaurieren
+                       bHash = bSavedHash;  // #i162175: restore '#' prefix
+               }
+               else
+               {
+                       bHash = bSavedHash;  // #i162175: restore '#' prefix 
for End If etc.
                }
+
+               // #i162175: Convert '#End If' to PP_ENDIF token
+               if (bHash && eCurTok == ENDIF)
+                       eCurTok = PP_ENDIF;
+
                return eCurTok;
        }
        // Sind Datentypen Keywords?
@@ -633,6 +651,7 @@ special:
        else
        {
                if( eTok == CLASSMODULE ||
+                       eTok == INTERFACE ||
                        eTok == IMPLEMENTS ||
                        eTok == PARAMARRAY ||
                        eTok == ENUM ||
@@ -644,6 +663,18 @@ special:
                }
        }
 
+       // #i162175: Convert '#'-prefixed tokens to preprocessor directive 
tokens
+       if (bHash)
+       {
+               switch (eCurTok)
+               {
+                       case IF:      eCurTok = PP_IF;      break;
+                       case ELSEIF:  eCurTok = PP_ELSEIF;  break;
+                       case ELSE:    eCurTok = PP_ELSE;    break;
+                       case _CONST_: eCurTok = PP_CONST;   break;
+               }
+       }
+
        bEos = IsEoln( eCurTok );
        return eCurTok;
 }
@@ -695,7 +726,8 @@ void SbiTokenizer::Hilite( SbTextPortions& rList )
                                aRes.eType = SB_NUMBER; break;
                        default:
                                if( ( eCurTok >= FIRSTKWD && eCurTok <= LASTKWD 
)
-                                || (eCurTok >= _CDECL_ ) )
+                                || (eCurTok >= _CDECL_ )
+                                || (eCurTok >= PP_IF && eCurTok <= PP_CONST) )
                                        aRes.eType = SB_KEYWORD;
                                else
                                        aRes.eType = SB_PUNCTUATION;
diff --git a/main/basic/source/inc/parser.hxx b/main/basic/source/inc/parser.hxx
index c7c1322ea2..465afdd04c 100644
--- a/main/basic/source/inc/parser.hxx
+++ b/main/basic/source/inc/parser.hxx
@@ -33,12 +33,14 @@
 typedef ::std::vector< String > StringVector;
 
 struct SbiParseStack;
+struct SbiPPFrame;
 
 class SbiParser : public SbiTokenizer
 {
        friend class SbiExpression;
 
        SbiParseStack* pStack;                  // Block-Stack
+       SbiPPFrame*   pPPStack;                 // #i162175: Preprocessor #If 
stack
        SbiProcDef* pProc;                              // aktuelle Prozedur
        SbiExprNode*  pWithVar;                 // aktuelle With-Variable
        SbiToken    eEndTok;                    // das Ende-Token
@@ -61,6 +63,19 @@ class SbiParser : public SbiTokenizer
        void DefEnum( sal_Bool bPrivate );      // Parse enum declaration
        void DefDeclare( sal_Bool bPrivate );
        void EnableCompatibility();
+       void PP_If();                           // #If
+       void PP_ElseIf();                       // #ElseIf
+       void PP_Else();                         // #Else
+       void PP_EndIf();                        // #End If
+       void PP_Const();                                // #Const
+       void AddPreprocConstants();     // Initialize platform constants
+       bool PP_EvalCondition();                // Evaluate #If condition 
expression
+       bool PP_EvalOrExpr();                   // Evaluate OR-level expression
+       bool PP_EvalAndExpr();          // Evaluate AND-level expression
+       bool PP_EvalNotExpr();          // Evaluate NOT expression
+       bool PP_EvalComparison();               // Evaluate comparison 
expression
+       double PP_EvalTerm();                   // Evaluate term 
(literal/constant/paren)
+       void PP_SkipToNextBranch();     // Skip tokens in inactive branch
 public:
        SbxArrayRef       rTypeArray;           // das Type-Array
        SbxArrayRef       rEnumArray;           // Enum types
@@ -69,6 +84,7 @@ public:
        SbiSymPool    aGlobals;                 // globale Variable
        SbiSymPool    aPublics;                 // modulglobale Variable
        SbiSymPool    aRtlSyms;                 // Runtime-Library
+       SbiSymPool    aPreprocConstants;  // Preprocessor constants (#Const)
        SbiCodeGen    aGen;                             // Code-Generator
        StarBASIC*        pBasic;                       // StarBASIC-Instanz
        SbiSymPool*       pPool;                        // aktueller Pool
diff --git a/main/basic/source/inc/token.hxx b/main/basic/source/inc/token.hxx
index 9d0d60ab0c..539e6b7a56 100644
--- a/main/basic/source/inc/token.hxx
+++ b/main/basic/source/inc/token.hxx
@@ -109,6 +109,8 @@ enum SbiToken {
        JS_PLUS, JS_MINUS, JS_MUL, JS_DIV, JS_MOD, JS_LOG_NOT, JS_BIT_NOT,
        JS_INC, JS_DEC, JS_LPAREN, JS_RPAREN, JS_LINDEX, JS_RINDEX
        , VBASUPPORT
+       , PP_IF, PP_ELSEIF, PP_ELSE, PP_ENDIF, PP_CONST
+       , INTERFACE
 };
 
 #ifdef SbiTokenSHAREDTMPUNDEF
diff --git a/main/oovbaapi/UnoApi_oovbaapi.mk b/main/oovbaapi/UnoApi_oovbaapi.mk
index 4ec8deabf7..3d767de4d6 100644
--- a/main/oovbaapi/UnoApi_oovbaapi.mk
+++ b/main/oovbaapi/UnoApi_oovbaapi.mk
@@ -76,7 +76,11 @@ $(eval $(call gb_UnoApiTarget_add_idlfiles,oovbaapi,\
        oovbaapi/ooo/vba/XExecutableDialog \
        oovbaapi/ooo/vba/XFileDialog \
        oovbaapi/ooo/vba/XFileDialogSelectedItems \
+       oovbaapi/ooo/vba/XDictionary \
+       oovbaapi/ooo/vba/XFile \
+       oovbaapi/ooo/vba/XFileSystemObject \
        oovbaapi/ooo/vba/XFileSearch \
+       oovbaapi/ooo/vba/XFolder \
        oovbaapi/ooo/vba/XFoundFiles \
        oovbaapi/ooo/vba/XFontBase \
        oovbaapi/ooo/vba/XGlobalsBase \
@@ -84,6 +88,7 @@ $(eval $(call gb_UnoApiTarget_add_idlfiles,oovbaapi,\
        oovbaapi/ooo/vba/XPageSetupBase \
        oovbaapi/ooo/vba/XPropValue \
        oovbaapi/ooo/vba/XVBAToOOEventDescGen \
+       oovbaapi/ooo/vba/XTextStream \
        oovbaapi/ooo/vba/XWindowBase \
        oovbaapi/ooo/vba/excel/XApplication \
        oovbaapi/ooo/vba/excel/XAxes \
diff --git a/main/oovbaapi/ooo/vba/XDictionary.idl 
b/main/oovbaapi/ooo/vba/XDictionary.idl
new file mode 100644
index 0000000000..8ae1094a73
--- /dev/null
+++ b/main/oovbaapi/ooo/vba/XDictionary.idl
@@ -0,0 +1,51 @@
+/**************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ *************************************************************/
+
+#ifndef __ooo_vba_XDictionary_idl__
+#define __ooo_vba_XDictionary_idl__
+
+#include <com/sun/star/uno/XInterface.idl>
+#include <ooo/vba/XHelperInterface.idl>
+
+module ooo { module vba {
+
+interface XDictionary
+{
+    interface ::ooo::vba::XHelperInterface;
+
+    [attribute] long CompareMode;
+    [attribute, readonly] long Count;
+
+    any Item( [in] any Key );
+    void ItemSet( [in] any Key, [in] any Value );
+
+    void Add( [in] any Key, [in] any Item );
+    boolean Exists( [in] any Key );
+    void Remove( [in] any Key );
+    void RemoveAll();
+    any Keys();
+    any Items();
+    void Key( [in] any Previous, [in] any Updated );
+};
+
+}; };
+
+#endif
diff --git a/main/oovbaapi/ooo/vba/XFile.idl b/main/oovbaapi/ooo/vba/XFile.idl
new file mode 100644
index 0000000000..f769b0dc6b
--- /dev/null
+++ b/main/oovbaapi/ooo/vba/XFile.idl
@@ -0,0 +1,56 @@
+/**************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ *************************************************************/
+
+
+#ifndef __ooo_vba_XFile_idl__
+#define __ooo_vba_XFile_idl__
+
+#include <com/sun/star/uno/XInterface.idl>
+#include <ooo/vba/XFileSystemObject.idl>
+
+module ooo { module vba {
+
+interface XFile
+{
+    interface ::ooo::vba::XHelperInterface;
+
+    [attribute, readonly] string Name;
+    [attribute, readonly] string Path;
+    [attribute, readonly] string Drive;
+    [attribute, readonly] string ParentFolder;
+    [attribute, readonly] string Type;
+    [attribute, readonly] boolean DateCreated;
+    [attribute, readonly] boolean DateLastModified;
+    [attribute, readonly] boolean DateLastAccessed;
+    [attribute, readonly] long Size;
+    [attribute] boolean Attributes;
+
+    XFileSystemObject GetFileSystemObject();
+    void Delete( [in] any force );
+    void Move( [in] string NewName );
+    void Copy( [in] string NewName, [in] /*Optional*/ any Overwrite );
+    XTextStream Open( [in] any Mode, [in] /*Optional*/ any Format );
+    XTextStream OpenAsTextStream( [in] any Mode, [in] /*Optional*/ any Format 
);
+};
+
+}; };
+
+#endif
diff --git a/main/oovbaapi/ooo/vba/XFileSystemObject.idl 
b/main/oovbaapi/ooo/vba/XFileSystemObject.idl
new file mode 100644
index 0000000000..cd8f6b745e
--- /dev/null
+++ b/main/oovbaapi/ooo/vba/XFileSystemObject.idl
@@ -0,0 +1,79 @@
+/**************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ *************************************************************/
+
+
+#ifndef __ooo_vba_XFileSystemObject_idl__
+#define __ooo_vba_XFileSystemObject_idl__
+
+#include <com/sun/star/uno/XInterface.idl>
+#include <ooo/vba/XHelperInterface.idl>
+
+module ooo { module vba {
+
+interface XFile;
+interface XFolder;
+interface XTextStream;
+
+interface XFileSystemObject
+{
+    interface ::ooo::vba::XHelperInterface;
+
+    boolean FileExists( [in] string FileName );
+    boolean FolderExists( [in] string FolderName );
+    boolean DriveExists( [in] string DriveName );
+
+    XFile GetFile( [in] string FileName );
+    XFolder GetFolder( [in] string FolderName );
+
+    string GetExtensionName( [in] string FileName );
+    string GetTempName();
+    string GetAbsolutePathName( [in] string Path );
+    string GetParentFolderName( [in] string Path );
+    string GetDriveName( [in] string Path );
+    string GetFileName( [in] string Path );
+    string GetSpecialFolder( [in] long SpecialFolder );
+
+    string BuildPath( [in] string Path, [in] string Name );
+    string GetDrive( [in] string Path );
+
+    void CopyFile( [in] string source, [in] string destination, [in] any 
overwrite );
+    void MoveFile( [in] string source, [in] string destination );
+    void DeleteFile( [in] string FileName, [in] any force );
+
+    void CreateFolder( [in] string FolderName );
+    void DeleteFolder( [in] string FolderName, [in] any force );
+    void CopyFolder( [in] string source, [in] string destination );
+    void MoveFolder( [in] string source, [in] string destination );
+
+    XFolder GetDriveDrive( [in] string DriveName );
+    boolean IsDriveReadOnly( [in] string DriveName );
+
+    XTextStream OpenTextFile( [in] string FileName, [in] any Mode, [in] any 
Create, [in] /*Optional*/ any Format );
+    XFile CreateTextFile( [in] string FileName, [in] any Overwrite, [in] 
/*Optional*/ any Unicode );
+    XFile CreateTextFileAt( [in] string FileName, [in] any Overwrite, [in] 
/*Optional*/ any Unicode );
+
+    XFile GetStandardSecuredInput( [in] string FileName, [in] string Password 
);
+    XFile GetStandardSecuredOutput( [in] string FileName, [in] string Password 
);
+};
+
+}; };
+
+#endif
diff --git a/main/oovbaapi/ooo/vba/XFolder.idl 
b/main/oovbaapi/ooo/vba/XFolder.idl
new file mode 100644
index 0000000000..65701a4ebc
--- /dev/null
+++ b/main/oovbaapi/ooo/vba/XFolder.idl
@@ -0,0 +1,59 @@
+/**************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ *************************************************************/
+
+
+#ifndef __ooo_vba_XFolder_idl__
+#define __ooo_vba_XFolder_idl__
+
+#include <com/sun/star/uno/XInterface.idl>
+#include <ooo/vba/XFileSystemObject.idl>
+#include <ooo/vba/XCollection.idl>
+
+module ooo { module vba {
+
+interface XFolder
+{
+    interface ::ooo::vba::XHelperInterface;
+
+    [attribute, readonly] string Name;
+    [attribute, readonly] string Path;
+    [attribute, readonly] string Drive;
+    [attribute, readonly] string ParentFolder;
+    [attribute, readonly] string Type;
+    [attribute, readonly] boolean DateCreated;
+    [attribute, readonly] boolean DateLastModified;
+    [attribute, readonly] boolean DateLastAccessed;
+    [attribute, readonly] long Size;
+
+    XFileSystemObject GetFileSystemObject();
+    void Delete( [in] any force );
+    void Move( [in] string NewName );
+    void Copy( [in] string NewName, [in] /*Optional*/ any Overwrite );
+
+    XCollection Files( [in] /*Optional*/ any Name );
+    XCollection SubFolders( [in] /*Optional*/ any Name );
+    XFolder Add( [in] string Name );
+    boolean IsRootFolder();
+};
+
+}; };
+
+#endif
diff --git a/main/oovbaapi/ooo/vba/XTextStream.idl 
b/main/oovbaapi/ooo/vba/XTextStream.idl
new file mode 100644
index 0000000000..b552e6f6e2
--- /dev/null
+++ b/main/oovbaapi/ooo/vba/XTextStream.idl
@@ -0,0 +1,67 @@
+/**************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ *************************************************************/
+
+
+#ifndef __ooo_vba_XTextStream_idl__
+#define __ooo_vba_XTextStream_idl__
+
+#include <com/sun/star/uno/XInterface.idl>
+#include <ooo/vba/XHelperInterface.idl>
+
+module ooo { module vba {
+
+interface XTextStream
+{
+    interface ::ooo::vba::XHelperInterface;
+
+    [attribute, readonly] boolean AtEndOfStream;
+    [attribute, readonly] boolean AtEndOfLine;
+    [attribute, readonly] long Line;
+    [attribute, readonly] long LineNumber;
+    [attribute, readonly] boolean EOS;
+
+    string Read( [in] any numchars );
+    string ReadAll();
+    string ReadLine();
+    string ReadLineBOM( [in] boolean bRemove );
+
+    void Write( [in] string content );
+    void WriteLineStr( [in] string content );
+    void WriteLine();
+    void WriteLineLong( [in] long content );
+    void WriteLineDouble( [in] double content );
+    void WriteLineBool( [in] boolean content );
+    void WriteLineDate( [in] double content );
+
+    void WriteBlankLines( [in] any n );
+    void WriteLineAny( [in] any content, [in] boolean newline );
+
+    void Close();
+    void Skip( [in] long n );
+    void SkipLine();
+
+    long getColumn();
+    long getCurrentLine();
+};
+
+}; };
+
+#endif
diff --git a/main/oovbaapi/ooo/vba/excel/XApplication.idl 
b/main/oovbaapi/ooo/vba/excel/XApplication.idl
index 3b479e8c24..e1c51fb941 100644
--- a/main/oovbaapi/ooo/vba/excel/XApplication.idl
+++ b/main/oovbaapi/ooo/vba/excel/XApplication.idl
@@ -55,6 +55,9 @@ interface XApplication
        [attribute, readonly] XWorksheet ActiveSheet;
     [attribute, readonly] ooo::vba::XAssistant Assistant;
        [attribute] long Calculation;
+        [attribute, readonly] long CalculationState;
+       [attribute] boolean ScreenUpdating;
+       [attribute] boolean Iteration;
        [attribute, readonly] XWorkbook ThisWorkbook;
        [attribute, readonly] string Name;
        [attribute] boolean DisplayAlerts;
@@ -62,7 +65,8 @@ interface XApplication
        [attribute] any CutCopyMode;
        [attribute] any StatusBar;
        [attribute] long Cursor;
-    [attribute] boolean EnableEvents;
+      [attribute] boolean EnableEvents;
+    [attribute] long EnableCancelKey;
     [attribute] string DefaultFilePath;
     [attribute, readonly] string LibraryPath;
     [attribute, readonly] string TemplatesPath;
diff --git a/main/oovbaapi/ooo/vba/excel/XRange.idl 
b/main/oovbaapi/ooo/vba/excel/XRange.idl
index 261c3b9635..807b81bfbf 100644
--- a/main/oovbaapi/ooo/vba/excel/XRange.idl
+++ b/main/oovbaapi/ooo/vba/excel/XRange.idl
@@ -76,6 +76,7 @@ interface XRange
        //interface ::ooo::vba::XHelperInterface;
 
        [attribute] any Value;
+       [attribute] any Value2;
        [attribute] any Formula;
        [attribute] any FormulaArray;
        [attribute] any FormulaR1C1;
@@ -85,6 +86,8 @@ interface XRange
        [attribute, readonly] string Text;
        [attribute, readonly] XRange EntireRow;
        [attribute, readonly] XRange EntireColumn;
+       [attribute, readonly] XRange Precedents;
+       [attribute, readonly] XRange Dependents;
        [attribute, readonly] XComment Comment;
        [attribute] any Hidden;
        [attribute] any ColumnWidth;
diff --git a/main/sc/Library_vbaobj.mk b/main/sc/Library_vbaobj.mk
index edb11b5e73..351714e557 100644
--- a/main/sc/Library_vbaobj.mk
+++ b/main/sc/Library_vbaobj.mk
@@ -66,6 +66,8 @@ $(eval $(call gb_Library_add_linked_libs,vbaobj,\
 
 $(eval $(call gb_Library_add_exception_objects,vbaobj,\
        sc/source/ui/vba/excelvbahelper \
+       sc/source/ui/vba/vbafilesystem \
+       sc/source/ui/vba/vbadictionary \
        sc/source/ui/vba/service \
        sc/source/ui/vba/vbaapplication \
        sc/source/ui/vba/vbaassistant \
diff --git a/main/sc/source/ui/vba/helperdecl.hxx 
b/main/sc/source/ui/vba/helperdecl.hxx
index 4ea4b6793a..063d862c0a 100644
--- a/main/sc/source/ui/vba/helperdecl.hxx
+++ b/main/sc/source/ui/vba/helperdecl.hxx
@@ -19,9 +19,6 @@
  *
  *************************************************************/
 
-#ifndef SC_VBA_HELPERDECL_HXX
-#define SC_VBA_HELPERDECL_HXX
-
 #ifndef SC_VBA_HELPERDECL_HXX
 #define SC_VBA_HELPERDECL_HXX
 #include <comphelper/servicedecl.hxx>
diff --git a/main/sc/source/ui/vba/service.cxx 
b/main/sc/source/ui/vba/service.cxx
index c3e36dcf91..01cd0a9641 100644
--- a/main/sc/source/ui/vba/service.cxx
+++ b/main/sc/source/ui/vba/service.cxx
@@ -70,7 +70,15 @@ namespace textframe
 {
 extern sdecl::ServiceDecl const serviceDecl;
 }
- 
+namespace filesystem
+{
+extern sdecl::ServiceDecl const serviceDecl;
+}
+namespace dictionary
+{
+extern sdecl::ServiceDecl const serviceDecl;
+}
+  
 extern "C"
 {
     SAL_DLLPUBLIC_EXPORT void SAL_CALL component_getImplementationEnvironment(
@@ -89,6 +97,10 @@ extern "C"
                pImplName, pServiceManager, pRegistryKey, range::serviceDecl, 
workbook::serviceDecl, worksheet::serviceDecl, globals::serviceDecl, 
window::serviceDecl, hyperlink::serviceDecl, application::serviceDecl );
     if( !pRet )
         pRet = component_getFactoryHelper( pImplName, pServiceManager, 
pRegistryKey, vbaeventshelper::serviceDecl, textframe::serviceDecl );
+    if( !pRet )
+        pRet = component_getFactoryHelper( pImplName, pServiceManager, 
pRegistryKey, filesystem::serviceDecl );
+    if( !pRet )
+        pRet = component_getFactoryHelper( pImplName, pServiceManager, 
pRegistryKey, dictionary::serviceDecl );
        OSL_TRACE("Ret is 0x%x", pRet);
        return pRet;
     }
diff --git a/main/sc/source/ui/vba/vbaapplication.cxx 
b/main/sc/source/ui/vba/vbaapplication.cxx
index e7ec55f99a..4e02208136 100644
--- a/main/sc/source/ui/vba/vbaapplication.cxx
+++ b/main/sc/source/ui/vba/vbaapplication.cxx
@@ -28,6 +28,8 @@
 #include <com/sun/star/view/XSelectionSupplier.hpp>
 #include <com/sun/star/lang/XServiceInfo.hpp>
 #include <ooo/vba/excel/XlCalculation.hpp>
+#include <ooo/vba/excel/XlCalculationState.hpp>
+#include <ooo/vba/excel/XlEnableCancelKey.hpp>
 #include <com/sun/star/sheet/XCellRangeReferrer.hpp>
 #include <com/sun/star/sheet/XCalculatable.hpp>
 #include <com/sun/star/frame/XLayoutManager.hpp>
@@ -117,6 +119,9 @@ struct ScVbaAppSettings
     sal_Int32 mnCalculation;
     sal_Bool mbDisplayAlerts;
     sal_Bool mbEnableEvents;
+    sal_Int32 mnEnableCancelKey;
+    sal_Bool mbScreenUpdating;
+    sal_Bool mbIteration;
 
     explicit ScVbaAppSettings();
 };
@@ -124,7 +129,10 @@ struct ScVbaAppSettings
 ScVbaAppSettings::ScVbaAppSettings() :
     mnCalculation( excel::XlCalculation::xlCalculationAutomatic ),
     mbDisplayAlerts( sal_True ),
-    mbEnableEvents( sal_True )
+    mbEnableEvents( sal_True ),
+    mnEnableCancelKey( excel::XlEnableCancelKey::xlInterrupt ),
+    mbScreenUpdating( sal_True ),
+    mbIteration( sal_False )
 {
 }
 
@@ -490,6 +498,14 @@ ScVbaApplication::setCalculation( ::sal_Int32 _calculation 
)
        }
 }
 
+// MS Excel VBA: Returns the state of calculation (xlCalculating, xlDone, 
xlPending).
+// Status: implemented - returns xlDone since AOO does not have a 
calculation-in-progress state
+::sal_Int32 SAL_CALL
+ScVbaApplication::getCalculationState()
+{
+       return excel::XlCalculationState::xlDone;
+}
+
 // MS Excel VBA: Returns the Windows collection or a single window by index.
 // Status: implemented - delegates to ScVbaWindows
 uno::Any SAL_CALL
@@ -797,6 +813,41 @@ ScVbaApplication::getEnableEvents()
        return mrAppSettings.mbEnableEvents;
 }
 
+// MS Excel VBA: Returns/sets the cancel key handling mode (EnableCancelKey).
+// Status: implemented - stored in shared settings
+::sal_Int32 SAL_CALL
+ScVbaApplication::getEnableCancelKey()
+{
+       return mrAppSettings.mnEnableCancelKey;
+}
+void SAL_CALL
+ScVbaApplication::setEnableCancelKey( ::sal_Int32 nKey )
+{
+       mrAppSettings.mnEnableCancelKey = nKey;
+}
+
+sal_Bool SAL_CALL
+ScVbaApplication::getScreenUpdating()
+{
+       return mrAppSettings.mbScreenUpdating;
+}
+void SAL_CALL
+ScVbaApplication::setScreenUpdating( sal_Bool bScreenUpdating )
+{
+       mrAppSettings.mbScreenUpdating = bScreenUpdating;
+}
+
+sal_Bool SAL_CALL
+ScVbaApplication::getIteration()
+{
+       return mrAppSettings.mbIteration;
+}
+void SAL_CALL
+ScVbaApplication::setIteration( sal_Bool bIteration )
+{
+       mrAppSettings.mbIteration = bIteration;
+}
+
 // MS Excel VBA: Recalculates all open workbooks.
 // Status: implemented - calls UNO XCalculatable::calculateAll
 void SAL_CALL
diff --git a/main/sc/source/ui/vba/vbaapplication.hxx 
b/main/sc/source/ui/vba/vbaapplication.hxx
index 1f1ca3bc18..b53de1faf5 100644
--- a/main/sc/source/ui/vba/vbaapplication.hxx
+++ b/main/sc/source/ui/vba/vbaapplication.hxx
@@ -128,9 +128,12 @@ public:
     // MS Excel VBA: Sets the calculation mode (automatic, manual, etc.).
     // Status: implemented - delegates to UNO XCalculatable
        virtual void SAL_CALL setCalculation( ::sal_Int32 _calculation );
+    // MS Excel VBA: Returns the state of calculation (xlCalculating, xlDone, 
xlPending).
+    // Status: implemented
+       virtual ::sal_Int32 SAL_CALL getCalculationState();
     // MS Excel VBA: Returns the current selection.
     // Status: implemented - supports shapes, cell ranges
-       virtual css::uno::Any SAL_CALL getSelection();
+    virtual css::uno::Any SAL_CALL getSelection();
     // MS Excel VBA: Returns the active workbook.
     // Status: implemented - creates ScVbaWorkbook if not already a VBA 
document
        virtual css::uno::Reference< ov::excel::XWorkbook > SAL_CALL 
getActiveWorkbook();
@@ -196,8 +199,21 @@ public:
     // MS Excel VBA: Sets whether events are enabled.
     // Status: implemented - stored in shared settings
        virtual void SAL_CALL setEnableEvents( sal_Bool bEnable );
+    // MS Excel VBA: Returns/sets the cancel key handling mode.
+    // Status: implemented - stored in shared settings
+       virtual ::sal_Int32 SAL_CALL getEnableCancelKey();
+       virtual void SAL_CALL setEnableCancelKey( ::sal_Int32 nKey );
+
+    // MS Excel VBA: Returns/sets whether screen updating is enabled.
+    // Status: implemented - stored in shared settings
+       virtual sal_Bool SAL_CALL getScreenUpdating();
+       virtual void SAL_CALL setScreenUpdating( sal_Bool bScreenUpdating );
+    // MS Excel VBA: Returns/sets whether iteration is enabled.
+    // Status: implemented - stored in shared settings
+       virtual sal_Bool SAL_CALL getIteration();
+       virtual void SAL_CALL setIteration( sal_Bool bIteration );
 
-    // MS Excel VBA: Returns the Windows collection or a single window by 
index.
+     // MS Excel VBA: Returns the Windows collection or a single window by 
index.
     // Status: implemented - delegates to ScVbaWindows
        virtual css::uno::Any SAL_CALL Windows( const css::uno::Any& aIndex );
     // MS Excel VBA: Pauses execution for the specified time (in seconds).
diff --git a/main/sc/source/ui/vba/vbadictionary.cxx 
b/main/sc/source/ui/vba/vbadictionary.cxx
new file mode 100644
index 0000000000..69d82ae4fd
--- /dev/null
+++ b/main/sc/source/ui/vba/vbadictionary.cxx
@@ -0,0 +1,191 @@
+/**************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ *************************************************************/
+
+#include "vbadictionary.hxx"
+#include <com/sun/star/uno/Any.hxx>
+#include <com/sun/star/uno/Sequence.hxx>
+#include <com/sun/star/lang/IllegalArgumentException.hpp>
+#include <vbahelper/helperdecl.hxx>
+#include <osl/diagnose.h>
+
+using namespace ::ooo::vba;
+using namespace ::com::sun::star;
+
+ScVbaDictionary::ScVbaDictionary( const css::uno::Reference< 
css::uno::XComponentContext >& xContext )
+    : ScVbaDictionary_BASE( xContext )
+    , mnCompareMode( 0 )
+{
+}
+
+ScVbaDictionary::ScVbaDictionary( const css::uno::Sequence< css::uno::Any >& 
/*args*/,
+                                  const css::uno::Reference< 
css::uno::XComponentContext >& xContext )
+    : ScVbaDictionary_BASE( xContext )
+    , mnCompareMode( 0 )
+{
+}
+
+ScVbaDictionary::~ScVbaDictionary()
+{
+}
+
+sal_Int32 ScVbaDictionary::findKeyIndex( const css::uno::Any& aKey ) const
+{
+    for ( sal_Int32 i = 0; i < static_cast<sal_Int32>(maKeys.size()); ++i )
+    {
+        if ( maKeys[i] == aKey )
+            return i;
+    }
+    return -1;
+}
+
+sal_Int32 SAL_CALL
+ScVbaDictionary::getCompareMode() throw (uno::RuntimeException)
+{
+    return mnCompareMode;
+}
+
+void SAL_CALL
+ScVbaDictionary::setCompareMode( sal_Int32 nMode ) throw 
(uno::RuntimeException)
+{
+    if ( mnCompareMode != nMode && getCount() > 0 )
+        throw lang::IllegalArgumentException();
+    mnCompareMode = nMode;
+}
+
+sal_Int32 SAL_CALL
+ScVbaDictionary::getCount() throw (uno::RuntimeException)
+{
+    return static_cast<sal_Int32>(maKeys.size());
+}
+
+uno::Any SAL_CALL
+ScVbaDictionary::Item( const uno::Any& Key ) throw (uno::RuntimeException)
+{
+    sal_Int32 idx = findKeyIndex( Key );
+    if ( idx >= 0 )
+        return maItems[idx];
+    return uno::Any();
+}
+
+void SAL_CALL
+ScVbaDictionary::ItemSet( const uno::Any& Key, const uno::Any& Value ) throw 
(uno::RuntimeException)
+{
+    sal_Int32 idx = findKeyIndex( Key );
+    if ( idx >= 0 )
+    {
+        maItems[idx] = Value;
+    }
+    else
+    {
+        Add( Key, Value );
+    }
+}
+
+void SAL_CALL
+ScVbaDictionary::Add( const uno::Any& Key, const uno::Any& Item ) throw 
(uno::RuntimeException)
+{
+    if ( findKeyIndex( Key ) >= 0 )
+        throw lang::IllegalArgumentException();
+    maKeys.push_back( Key );
+    maItems.push_back( Item );
+}
+
+sal_Bool SAL_CALL
+ScVbaDictionary::Exists( const uno::Any& Key ) throw (uno::RuntimeException)
+{
+    return findKeyIndex( Key ) >= 0 ? sal_True : sal_False;
+}
+
+void SAL_CALL
+ScVbaDictionary::Remove( const uno::Any& Key ) throw (uno::RuntimeException)
+{
+    sal_Int32 idx = findKeyIndex( Key );
+    if ( idx < 0 )
+        return;
+    maKeys.erase( maKeys.begin() + idx );
+    maItems.erase( maItems.begin() + idx );
+}
+
+void SAL_CALL
+ScVbaDictionary::RemoveAll() throw (uno::RuntimeException)
+{
+    maKeys.clear();
+    maItems.clear();
+}
+
+uno::Any SAL_CALL
+ScVbaDictionary::Keys() throw (uno::RuntimeException)
+{
+    uno::Sequence<uno::Any> aKeys(maKeys.size());
+    for ( sal_Int32 i = 0; i < static_cast<sal_Int32>(maKeys.size()); ++i )
+        aKeys[i] = maKeys[i];
+    uno::Any aResult;
+    aResult <<= aKeys;
+    return aResult;
+}
+
+uno::Any SAL_CALL
+ScVbaDictionary::Items() throw (uno::RuntimeException)
+{
+    uno::Sequence<uno::Any> aItems(maItems.size());
+    for ( sal_Int32 i = 0; i < static_cast<sal_Int32>(maItems.size()); ++i )
+        aItems[i] = maItems[i];
+    uno::Any aResult;
+    aResult <<= aItems;
+    return aResult;
+}
+
+void SAL_CALL
+ScVbaDictionary::Key( const uno::Any& Previous, const uno::Any& Updated ) 
throw (uno::RuntimeException)
+{
+    sal_Int32 idx = findKeyIndex( Previous );
+    if ( idx >= 0 )
+        maKeys[idx] = Updated;
+}
+
+rtl::OUString&
+ScVbaDictionary::getServiceImplName()
+{
+    static rtl::OUString 
sImplName(RTL_CONSTASCII_USTRINGPARAM("ScVbaDictionary"));
+    return sImplName;
+}
+
+css::uno::Sequence< rtl::OUString >
+ScVbaDictionary::getServiceNames()
+{
+    static css::uno::Sequence< rtl::OUString > aServiceNames;
+    if ( aServiceNames.getLength() == 0 )
+    {
+        aServiceNames.realloc( 1 );
+        aServiceNames[0] = 
rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ooo.vba.Scripting.Dictionary"));
+    }
+    return aServiceNames;
+}
+
+namespace dictionary
+{
+namespace sdecl = comphelper::service_decl;
+sdecl::vba_service_class_<ScVbaDictionary, sdecl::with_args<true>> serviceImpl;
+extern sdecl::ServiceDecl const serviceDecl(
+    serviceImpl,
+    "ScVbaDictionary",
+    "ooo.vba.Scripting.Dictionary" );
+}
diff --git a/main/sc/source/ui/vba/vbadictionary.hxx 
b/main/sc/source/ui/vba/vbadictionary.hxx
new file mode 100644
index 0000000000..df871cbe08
--- /dev/null
+++ b/main/sc/source/ui/vba/vbadictionary.hxx
@@ -0,0 +1,72 @@
+/**************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ *************************************************************/
+
+#ifndef SC_VBA_DICTIONARY_HXX
+#define SC_VBA_DICTIONARY_HXX
+
+#include <ooo/vba/XDictionary.hpp>
+#include <vbahelper/vbahelperinterface.hxx>
+#include <vbahelper/helperdecl.hxx>
+#include <cppuhelper/implbase1.hxx>
+#include <com/sun/star/uno/Sequence.hxx>
+#include <com/sun/star/uno/Any.hxx>
+#include <vector>
+
+namespace css = ::com::sun::star;
+
+typedef InheritedHelperInterfaceImpl1< ooo::vba::XDictionary > 
ScVbaDictionary_BASE;
+
+class ScVbaDictionary : public ScVbaDictionary_BASE
+{
+private:
+    std::vector< css::uno::Any > maKeys;
+    std::vector< css::uno::Any > maItems;
+    sal_Int32 mnCompareMode;
+
+    sal_Int32 findKeyIndex( const css::uno::Any& aKey ) const;
+
+public:
+    ScVbaDictionary( const css::uno::Reference< css::uno::XComponentContext >& 
xContext );
+    ScVbaDictionary( const css::uno::Sequence< css::uno::Any >& args,
+                     const css::uno::Reference< css::uno::XComponentContext >& 
xContext );
+    virtual ~ScVbaDictionary();
+
+    virtual sal_Int32 SAL_CALL getCompareMode() throw 
(css::uno::RuntimeException);
+    virtual void SAL_CALL setCompareMode( sal_Int32 Mode ) throw 
(css::uno::RuntimeException);
+
+    virtual sal_Int32 SAL_CALL getCount() throw (css::uno::RuntimeException);
+
+    virtual css::uno::Any SAL_CALL Item( const css::uno::Any& Key ) throw 
(css::uno::RuntimeException);
+    virtual void SAL_CALL ItemSet( const css::uno::Any& Key, const 
css::uno::Any& Value ) throw (css::uno::RuntimeException);
+
+    virtual void SAL_CALL Add( const css::uno::Any& Key, const css::uno::Any& 
Item ) throw (css::uno::RuntimeException);
+    virtual sal_Bool SAL_CALL Exists( const css::uno::Any& Key ) throw 
(css::uno::RuntimeException);
+    virtual void SAL_CALL Remove( const css::uno::Any& Key ) throw 
(css::uno::RuntimeException);
+    virtual void SAL_CALL RemoveAll() throw (css::uno::RuntimeException);
+    virtual css::uno::Any SAL_CALL Keys() throw (css::uno::RuntimeException);
+    virtual css::uno::Any SAL_CALL Items() throw (css::uno::RuntimeException);
+    virtual void SAL_CALL Key( const css::uno::Any& Previous, const 
css::uno::Any& Updated ) throw (css::uno::RuntimeException);
+
+    virtual rtl::OUString& getServiceImplName();
+    virtual css::uno::Sequence< rtl::OUString > getServiceNames();
+};
+
+#endif
diff --git a/main/sc/source/ui/vba/vbafiledialog.hxx 
b/main/sc/source/ui/vba/vbafiledialog.hxx
index 7885540839..e727dad17d 100644
--- a/main/sc/source/ui/vba/vbafiledialog.hxx
+++ b/main/sc/source/ui/vba/vbafiledialog.hxx
@@ -85,7 +85,6 @@ private:
     rtl::OUString m_sTitle;
     sal_Bool m_bAllowMultiSelect;
     css::uno::Sequence< rtl::OUString > m_sSelectedItems;
-    css::uno::Reference< css::frame::XModel > m_xModel;
     VbaFileDialogSelectedItems *m_pSelectedItems;
     VbaFileDialogSelectedObj m_FileDialogSelectedObj;
 };
diff --git a/main/sc/source/ui/vba/vbafilesystem.cxx 
b/main/sc/source/ui/vba/vbafilesystem.cxx
new file mode 100644
index 0000000000..8d29ba7fd0
--- /dev/null
+++ b/main/sc/source/ui/vba/vbafilesystem.cxx
@@ -0,0 +1,320 @@
+/**************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ *************************************************************/
+
+#include "vbafilesystem.hxx"
+#include <osl/file.hxx>
+#include <osl/process.h>
+#include <com/sun/star/beans/XPropertySet.hpp>
+#include <com/sun/star/lang/XMultiComponentFactory.hpp>
+#include <com/sun/star/uno/Any.hxx>
+#include <comphelper/processfactory.hxx>
+#include <tools/string.hxx>
+
+using namespace ::ooo::vba;
+using namespace ::com::sun::star;
+
+ScVbaFileSystemObject::ScVbaFileSystemObject(
+    const css::uno::Reference< css::uno::XComponentContext >& xContext)
+    : ScVbaFileSystemObject_BASE(xContext)
+{
+}
+
+ScVbaFileSystemObject::ScVbaFileSystemObject(
+    const css::uno::Sequence< css::uno::Any >& /*args*/,
+    const css::uno::Reference< css::uno::XComponentContext >& xContext)
+    : ScVbaFileSystemObject_BASE(xContext)
+{
+}
+
+ScVbaFileSystemObject::~ScVbaFileSystemObject()
+{
+}
+
+static rtl::OUString toUrl(const rtl::OUString& path)
+{
+    rtl::OUString url;
+    if (path.match(rtl::OUString::createFromAscii("file://")))
+        return path;
+    osl::FileBase::getFileURLFromSystemPath(path, url);
+    return url;
+}
+
+sal_Bool SAL_CALL
+ScVbaFileSystemObject::FileExists(const rtl::OUString& FileName) throw 
(uno::RuntimeException)
+{
+    rtl::OUString url = toUrl(FileName);
+    osl::DirectoryItem item;
+    osl::FileBase::RC eError = osl::DirectoryItem::get(url, item);
+    if (eError != osl::FileBase::E_None)
+        return sal_False;
+    osl::FileStatus status(osl_FileStatus_Mask_Type);
+    item.getFileStatus(status);
+    return status.getFileType() == osl::FileStatus::Regular ? sal_True : 
sal_False;
+}
+
+sal_Bool SAL_CALL
+ScVbaFileSystemObject::FolderExists(const rtl::OUString& FolderName) throw 
(uno::RuntimeException)
+{
+    rtl::OUString url = toUrl(FolderName);
+    osl::DirectoryItem item;
+    osl::FileBase::RC eError = osl::DirectoryItem::get(url, item);
+    if (eError != osl::FileBase::E_None)
+        return sal_False;
+    osl::FileStatus status(osl_FileStatus_Mask_Type);
+    item.getFileStatus(status);
+    return status.getFileType() == osl::FileStatus::Directory ? sal_True : 
sal_False;
+}
+
+sal_Bool SAL_CALL
+ScVbaFileSystemObject::DriveExists(const rtl::OUString& DriveName) throw 
(uno::RuntimeException)
+{
+    return FileExists(DriveName);
+}
+
+uno::Reference< XFile > SAL_CALL
+ScVbaFileSystemObject::GetFile(const rtl::OUString& FileName) throw 
(uno::RuntimeException)
+{
+    if (!FileExists(FileName))
+        throw lang::IllegalArgumentException();
+    // Return a simple stub File object - full implementation would need XFile
+    return nullptr;
+}
+
+uno::Reference< XFolder > SAL_CALL
+ScVbaFileSystemObject::GetFolder(const rtl::OUString& FolderName) throw 
(uno::RuntimeException)
+{
+    if (!FolderExists(FolderName))
+        throw lang::IllegalArgumentException();
+    // Return null - Folder implementation would require XFolder UNO service
+    // For now, return null to avoid creating a new service
+    return nullptr;
+}
+
+rtl::OUString SAL_CALL
+ScVbaFileSystemObject::GetExtensionName(const rtl::OUString& FileName) throw 
(uno::RuntimeException)
+{
+    sal_Int32 lastDot = FileName.lastIndexOf('.');
+    if (lastDot == -1)
+        return rtl::OUString();
+    return FileName.copy(lastDot + 1);
+}
+
+rtl::OUString SAL_CALL
+ScVbaFileSystemObject::GetTempName() throw (uno::RuntimeException)
+{
+    rtl::OUString aTemp = rtl::OUString::createFromAscii( "temp.tmp" );
+    return aTemp;
+}
+
+rtl::OUString SAL_CALL
+ScVbaFileSystemObject::GetAbsolutePathName(const rtl::OUString& Path) throw 
(uno::RuntimeException)
+{
+    return Path;
+}
+
+rtl::OUString SAL_CALL
+ScVbaFileSystemObject::GetParentFolderName(const rtl::OUString& Path) throw 
(uno::RuntimeException)
+{
+    sal_Int32 lastSep = Path.lastIndexOf('/');
+    if (lastSep == -1)
+        lastSep = Path.lastIndexOf('\\');
+    if (lastSep == -1)
+        return rtl::OUString();
+    return Path.copy(0, lastSep);
+}
+
+rtl::OUString SAL_CALL
+ScVbaFileSystemObject::GetDriveName(const rtl::OUString& Path) throw 
(uno::RuntimeException)
+{
+#if defined(WNT) || defined(WIN)
+    if (Path.getLength() >= 2 && Path[1] == ':')
+        return Path.copy(0, 2);
+#endif
+    return rtl::OUString();
+}
+
+rtl::OUString SAL_CALL
+ScVbaFileSystemObject::GetFileName(const rtl::OUString& Path) throw 
(uno::RuntimeException)
+{
+    sal_Int32 lastSep = Path.lastIndexOf('/');
+    if (lastSep == -1)
+        lastSep = Path.lastIndexOf('\\');
+    if (lastSep == -1)
+        return Path;
+    return Path.copy(lastSep + 1);
+}
+
+rtl::OUString SAL_CALL
+ScVbaFileSystemObject::BuildPath(const rtl::OUString& Path, const 
rtl::OUString& Name) throw (uno::RuntimeException)
+{
+    if (Path.isEmpty())
+        return Name;
+    sal_Int32 lastSep = Path.lastIndexOf('/');
+    if (lastSep == -1)
+        lastSep = Path.lastIndexOf('\\');
+    rtl::OUString sep = (lastSep != -1 && Path[lastSep] == '/') ?
+        rtl::OUString::createFromAscii("/") : 
rtl::OUString::createFromAscii("\\");
+    if (Path.lastIndexOf(sep) == Path.getLength() - 1)
+        return Path + Name;
+    return Path + sep + Name;
+}
+
+void SAL_CALL
+ScVbaFileSystemObject::CopyFile(const rtl::OUString& source, const 
rtl::OUString& destination,
+                                const css::uno::Any& /*overwrite*/) throw 
(uno::RuntimeException)
+{
+    rtl::OUString srcUrl = toUrl(source);
+    rtl::OUString dstUrl = toUrl(destination);
+    osl::FileBase::RC eError = osl::File::copy(srcUrl, dstUrl);
+    if (eError != osl::FileBase::E_None)
+        throw io::IOException();
+}
+
+void SAL_CALL
+ScVbaFileSystemObject::MoveFile(const rtl::OUString& source, const 
rtl::OUString& destination) throw (uno::RuntimeException)
+{
+    rtl::OUString srcUrl = toUrl(source);
+    rtl::OUString dstUrl = toUrl(destination);
+    osl::FileBase::RC eError = osl::File::move(srcUrl, dstUrl);
+    if (eError != osl::FileBase::E_None)
+        throw io::IOException();
+}
+
+void SAL_CALL
+ScVbaFileSystemObject::DeleteFile(const rtl::OUString& FileName, const 
css::uno::Any& /*force*/) throw (uno::RuntimeException)
+{
+    rtl::OUString url = toUrl(FileName);
+    osl::FileBase::RC eError = osl::File::remove(url);
+    if (eError != osl::FileBase::E_None)
+        throw io::IOException();
+}
+
+void SAL_CALL
+ScVbaFileSystemObject::CreateFolder(const rtl::OUString& FolderName) throw 
(uno::RuntimeException)
+{
+    rtl::OUString url = toUrl(FolderName);
+    osl::FileBase::RC eError = osl::Directory::create(url);
+    if (eError != osl::FileBase::E_None)
+        throw io::IOException();
+}
+
+void SAL_CALL
+ScVbaFileSystemObject::DeleteFolder(const rtl::OUString& FolderName, const 
css::uno::Any& /*force*/) throw (uno::RuntimeException)
+{
+    rtl::OUString url = toUrl(FolderName);
+    osl::FileBase::RC eError = osl::Directory::remove(url);
+    if (eError != osl::FileBase::E_None)
+        throw io::IOException();
+}
+
+uno::Reference< XTextStream > SAL_CALL
+ScVbaFileSystemObject::OpenTextFile(const rtl::OUString& FileName, const 
css::uno::Any& /*Mode*/,
+                                    const css::uno::Any& Create, const 
css::uno::Any& /*Format*/) throw (uno::RuntimeException)
+{
+    return nullptr;
+}
+
+rtl::OUString SAL_CALL
+ScVbaFileSystemObject::GetSpecialFolder( sal_Int32 /*SpecialFolder*/ ) throw 
(uno::RuntimeException)
+{
+    return rtl::OUString();
+}
+
+rtl::OUString SAL_CALL
+ScVbaFileSystemObject::GetDrive( const rtl::OUString& /*Path*/ ) throw 
(uno::RuntimeException)
+{
+    return rtl::OUString();
+}
+
+void SAL_CALL
+ScVbaFileSystemObject::CopyFolder( const rtl::OUString& /*source*/, const 
rtl::OUString& /*destination*/ ) throw (uno::RuntimeException)
+{
+}
+
+void SAL_CALL
+ScVbaFileSystemObject::MoveFolder( const rtl::OUString& /*source*/, const 
rtl::OUString& /*destination*/ ) throw (uno::RuntimeException)
+{
+}
+
+uno::Reference< XFolder > SAL_CALL
+ScVbaFileSystemObject::GetDriveDrive( const rtl::OUString& /*DriveName*/ ) 
throw (uno::RuntimeException)
+{
+    return nullptr;
+}
+
+sal_Bool SAL_CALL
+ScVbaFileSystemObject::IsDriveReadOnly( const rtl::OUString& /*DriveName*/ ) 
throw (uno::RuntimeException)
+{
+    return sal_False;
+}
+
+uno::Reference< XFile > SAL_CALL
+ScVbaFileSystemObject::CreateTextFile( const rtl::OUString& /*FileName*/, 
const css::uno::Any& /*Overwrite*/, const css::uno::Any& /*Unicode*/ ) throw 
(uno::RuntimeException)
+{
+    return nullptr;
+}
+
+uno::Reference< XFile > SAL_CALL
+ScVbaFileSystemObject::CreateTextFileAt( const rtl::OUString& /*FileName*/, 
const css::uno::Any& /*Overwrite*/, const css::uno::Any& /*Unicode*/ ) throw 
(uno::RuntimeException)
+{
+    return nullptr;
+}
+
+uno::Reference< XFile > SAL_CALL
+ScVbaFileSystemObject::GetStandardSecuredInput( const rtl::OUString& 
/*FileName*/, const rtl::OUString& /*Password*/ ) throw (uno::RuntimeException)
+{
+    return nullptr;
+}
+
+uno::Reference< XFile > SAL_CALL
+ScVbaFileSystemObject::GetStandardSecuredOutput( const rtl::OUString& 
/*FileName*/, const rtl::OUString& /*Password*/ ) throw (uno::RuntimeException)
+{
+    return nullptr;
+}
+
+rtl::OUString&
+ScVbaFileSystemObject::getServiceImplName()
+{
+    static rtl::OUString 
sImplName(RTL_CONSTASCII_USTRINGPARAM("ScVbaFileSystemObject"));
+    return sImplName;
+}
+
+css::uno::Sequence< rtl::OUString >
+ScVbaFileSystemObject::getServiceNames()
+{
+    static css::uno::Sequence< rtl::OUString > aServiceNames;
+    if (aServiceNames.getLength() == 0)
+    {
+        aServiceNames.realloc(1);
+        aServiceNames[0] = 
rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ooo.vba.FileSystemObject"));
+    }
+    return aServiceNames;
+}
+
+namespace filesystem
+{
+namespace sdecl = comphelper::service_decl;
+sdecl::vba_service_class_<ScVbaFileSystemObject, sdecl::with_args<true>> 
serviceImpl;
+extern sdecl::ServiceDecl const serviceDecl(
+    serviceImpl,
+    "ScVbaFileSystemObject",
+    "ooo.vba.FileSystemObject" );
+}
diff --git a/main/sc/source/ui/vba/vbafilesystem.hxx 
b/main/sc/source/ui/vba/vbafilesystem.hxx
new file mode 100644
index 0000000000..99f4fe8329
--- /dev/null
+++ b/main/sc/source/ui/vba/vbafilesystem.hxx
@@ -0,0 +1,89 @@
+/**************************************************************
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ *************************************************************/
+
+#ifndef SC_VBA_FILESYSTEMOBJECT_HXX
+#define SC_VBA_FILESYSTEMOBJECT_HXX
+
+#include <ooo/vba/XFileSystemObject.hpp>
+#include <ooo/vba/XFile.hpp>
+#include <ooo/vba/XFolder.hpp>
+#include <ooo/vba/XTextStream.hpp>
+#include <ooo/vba/XCollection.hpp>
+#include <vbahelper/vbahelperinterface.hxx>
+#include <vbahelper/helperdecl.hxx>
+#include <cppuhelper/implbase1.hxx>
+#include <com/sun/star/uno/Sequence.hxx>
+
+namespace css = ::com::sun::star;
+
+typedef InheritedHelperInterfaceImpl1< ooo::vba::XFileSystemObject > 
ScVbaFileSystemObject_BASE;
+
+class ScVbaFileSystemObject : public ScVbaFileSystemObject_BASE
+{
+public:
+    ScVbaFileSystemObject(const css::uno::Reference< 
css::uno::XComponentContext >& xContext);
+    ScVbaFileSystemObject(const css::uno::Sequence< css::uno::Any >& args,
+                          const css::uno::Reference< 
css::uno::XComponentContext >& xContext);
+    virtual ~ScVbaFileSystemObject();
+
+    virtual sal_Bool SAL_CALL FileExists(const ::rtl::OUString& FileName) 
throw (css::uno::RuntimeException);
+    virtual sal_Bool SAL_CALL FolderExists(const ::rtl::OUString& FolderName) 
throw (css::uno::RuntimeException);
+    virtual sal_Bool SAL_CALL DriveExists(const ::rtl::OUString& DriveName) 
throw (css::uno::RuntimeException);
+
+    virtual css::uno::Reference< ooo::vba::XFile > SAL_CALL GetFile(const 
::rtl::OUString& FileName) throw (css::uno::RuntimeException);
+    virtual css::uno::Reference< ooo::vba::XFolder > SAL_CALL GetFolder(const 
::rtl::OUString& FolderName) throw (css::uno::RuntimeException);
+
+    virtual ::rtl::OUString SAL_CALL GetExtensionName(const ::rtl::OUString& 
FileName) throw (css::uno::RuntimeException);
+    virtual ::rtl::OUString SAL_CALL GetTempName() throw 
(css::uno::RuntimeException);
+    virtual ::rtl::OUString SAL_CALL GetAbsolutePathName(const 
::rtl::OUString& Path) throw (css::uno::RuntimeException);
+    virtual ::rtl::OUString SAL_CALL GetParentFolderName(const 
::rtl::OUString& Path) throw (css::uno::RuntimeException);
+    virtual ::rtl::OUString SAL_CALL GetDriveName(const ::rtl::OUString& Path) 
throw (css::uno::RuntimeException);
+    virtual ::rtl::OUString SAL_CALL GetFileName(const ::rtl::OUString& Path) 
throw (css::uno::RuntimeException);
+
+    virtual ::rtl::OUString SAL_CALL BuildPath(const ::rtl::OUString& Path, 
const ::rtl::OUString& Name) throw (css::uno::RuntimeException);
+
+    virtual void SAL_CALL CopyFile(const ::rtl::OUString& source, const 
::rtl::OUString& destination, const css::uno::Any& overwrite) throw 
(css::uno::RuntimeException);
+    virtual void SAL_CALL MoveFile(const ::rtl::OUString& source, const 
::rtl::OUString& destination) throw (css::uno::RuntimeException);
+    virtual void SAL_CALL DeleteFile(const ::rtl::OUString& FileName, const 
css::uno::Any& force) throw (css::uno::RuntimeException);
+
+    virtual void SAL_CALL CreateFolder(const ::rtl::OUString& FolderName) 
throw (css::uno::RuntimeException);
+    virtual void SAL_CALL DeleteFolder(const ::rtl::OUString& FolderName, 
const css::uno::Any& force) throw (css::uno::RuntimeException);
+
+    virtual css::uno::Reference< ooo::vba::XTextStream > SAL_CALL OpenTextFile(
+        const ::rtl::OUString& FileName, const css::uno::Any& Mode,
+        const css::uno::Any& Create, const css::uno::Any& Format) throw 
(css::uno::RuntimeException);
+
+    virtual ::rtl::OUString SAL_CALL GetSpecialFolder( sal_Int32 SpecialFolder 
) throw (css::uno::RuntimeException);
+    virtual ::rtl::OUString SAL_CALL GetDrive( const ::rtl::OUString& Path ) 
throw (css::uno::RuntimeException);
+    virtual void SAL_CALL CopyFolder( const ::rtl::OUString& source, const 
::rtl::OUString& destination ) throw (css::uno::RuntimeException);
+    virtual void SAL_CALL MoveFolder( const ::rtl::OUString& source, const 
::rtl::OUString& destination ) throw (css::uno::RuntimeException);
+    virtual css::uno::Reference< ooo::vba::XFolder > SAL_CALL GetDriveDrive( 
const ::rtl::OUString& DriveName ) throw (css::uno::RuntimeException);
+    virtual sal_Bool SAL_CALL IsDriveReadOnly( const ::rtl::OUString& 
DriveName ) throw (css::uno::RuntimeException);
+    virtual css::uno::Reference< ooo::vba::XFile > SAL_CALL CreateTextFile( 
const ::rtl::OUString& FileName, const css::uno::Any& Overwrite, const 
css::uno::Any& Unicode ) throw (css::uno::RuntimeException);
+    virtual css::uno::Reference< ooo::vba::XFile > SAL_CALL CreateTextFileAt( 
const ::rtl::OUString& FileName, const css::uno::Any& Overwrite, const 
css::uno::Any& Unicode ) throw (css::uno::RuntimeException);
+    virtual css::uno::Reference< ooo::vba::XFile > SAL_CALL 
GetStandardSecuredInput( const ::rtl::OUString& FileName, const 
::rtl::OUString& Password ) throw (css::uno::RuntimeException);
+    virtual css::uno::Reference< ooo::vba::XFile > SAL_CALL 
GetStandardSecuredOutput( const ::rtl::OUString& FileName, const 
::rtl::OUString& Password ) throw (css::uno::RuntimeException);
+
+    virtual rtl::OUString& getServiceImplName();
+    virtual css::uno::Sequence< rtl::OUString > getServiceNames();
+};
+
+#endif
diff --git a/main/sc/source/ui/vba/vbarange.cxx 
b/main/sc/source/ui/vba/vbarange.cxx
index 14ec09729b..e56be2294b 100644
--- a/main/sc/source/ui/vba/vbarange.cxx
+++ b/main/sc/source/ui/vba/vbarange.cxx
@@ -165,6 +165,7 @@
 #include "vbaglobals.hxx"
 #include "vbastyle.hxx"
 #include <vector>
+#include <set>
 #include <vbahelper/vbacollectionimpl.hxx>
 // begin test includes
 #include <com/sun/star/sheet/FunctionArgument.hpp>
@@ -948,6 +949,75 @@ void CellValueGetter::visitNode( sal_Int32 x, sal_Int32 y, 
const uno::Reference<
        processValue( x,y,aValue );
 }
 
+
+// MS Excel VBA: Internal helper class for getting cell values without type 
conversion (Value2).
+// Unlike CellValueGetter, this does not wrap date values in 
oleautomation::Date objects.
+// Status: internal helper
+class CellValue2Getter : public ValueGetter
+{
+protected:
+       uno::Any maValue;
+       uno::TypeClass mTypeClass;
+public:
+       CellValue2Getter() {}
+       virtual void visitNode( sal_Int32 x, sal_Int32 y, const uno::Reference< 
table::XCell >& xCell );
+       virtual void processValue( sal_Int32 x, sal_Int32 y, const uno::Any& 
aValue );
+       const uno::Any& getValue() const { return maValue; }
+};
+
+void
+CellValue2Getter::processValue(  sal_Int32 /*x*/, sal_Int32 /*y*/, const 
uno::Any& aValue )
+{
+       maValue = aValue;
+}
+// MS Excel VBA: Internal - visits a cell node to get its Value2 (raw value).
+// Status: internal helper
+void CellValue2Getter::visitNode( sal_Int32 x, sal_Int32 y, const 
uno::Reference< table::XCell >& xCell )
+{
+       uno::Any aValue;
+       table::CellContentType eType = xCell->getType();
+       if( eType == table::CellContentType_VALUE || eType == 
table::CellContentType_FORMULA )
+       {
+               if ( eType == table::CellContentType_FORMULA )
+               {
+                       rtl::OUString sFormula = xCell->getFormula();
+                       if ( sFormula.equals( rtl::OUString( 
RTL_CONSTASCII_USTRINGPARAM("=TRUE()") ) ) )
+                               aValue <<= sal_True;
+                       else if ( sFormula.equals( rtl::OUString( 
RTL_CONSTASCII_USTRINGPARAM("=FALSE()") ) ) )
+                               aValue <<= sal_False;
+                       else
+                       {
+                               uno::Reference< beans::XPropertySet > xProp( 
xCell, uno::UNO_QUERY_THROW );
+                               table::CellContentType eFormulaType = 
table::CellContentType_VALUE;
+                               xProp->getPropertyValue( rtl::OUString( 
RTL_CONSTASCII_USTRINGPARAM("FormulaResultType" ) ) ) >>= eFormulaType;
+                               if ( eFormulaType == 
table::CellContentType_TEXT )
+                               {
+                                       uno::Reference< text::XTextRange > 
xTextRange(xCell, ::uno::UNO_QUERY_THROW);
+                                       aValue <<= xTextRange->getString();
+                               }
+                               else
+                                       aValue <<= xCell->getValue();
+                       }
+               }
+               else
+               {
+                       // Value2: return raw double without Date/Currency 
wrapping
+                       uno::Reference< table::XCellRange > xRange( xCell, 
uno::UNO_QUERY_THROW );
+                       NumFormatHelper cellFormat( xRange );
+                       if ( cellFormat.isBooleanType() )
+                               aValue = uno::makeAny( ( xCell->getValue() != 
0.0 ) );
+                       else
+                               aValue <<= xCell->getValue();
+               }
+       }
+       if( eType == table::CellContentType_TEXT )
+       {
+               uno::Reference< text::XTextRange > xTextRange(xCell, 
::uno::UNO_QUERY_THROW);
+               aValue <<= xTextRange->getString();
+       }
+       processValue( x,y,aValue );
+}
+
 // MS Excel VBA: Internal helper class for setting formula values.
 // Status: internal helper
 class CellFormulaValueSetter : public CellValueSetter
@@ -1727,20 +1797,53 @@ ScVbaRange::setValue( const uno::Any  &aValue )
        lcl_NotifyRangeChanges( getScDocShell()->GetModel(), 
getCellRangesBase() );
 }
 
+// MS Excel VBA: Gets the value of the range as a Variant (Value2).
+// Unlike Value, Value2 does not convert date/currency cells.
+// Status: implemented
+uno::Any SAL_CALL
+ScVbaRange::getValue2()
+{
+       if ( m_Areas->getCount() > 1 )
+       {
+               uno::Reference< excel::XRange > xRange( getArea( 0 ), 
uno::UNO_QUERY_THROW );
+               return xRange->getValue2();
+       }
+
+       CellValue2Getter valueGetter;
+       return getValue( valueGetter );
+}
+
+void SAL_CALL
+ScVbaRange::setValue2( const uno::Any& rValue )
+{
+       setValue( rValue );
+}
+
+uno::Any SAL_CALL
+ScVbaRange::getAddIndent()
+{
+       return uno::Any( false );
+}
+
+void SAL_CALL
+ScVbaRange::setAddIndent( const uno::Any& /*rAddIndent*/ )
+{
+}
+
 // MS Excel VBA: Clears the entire range.
 // Status: implemented
 void SAL_CALL
 ScVbaRange::Clear()
 {
     using namespace ::com::sun::star::sheet::CellFlags;
-       sal_Int32 nFlags = VALUE | DATETIME | STRING | FORMULA | HARDATTR | 
EDITATTR | FORMATTED;
-       ClearContents( nFlags, true );
-       // Fire the range change event
-       lcl_NotifyRangeChanges( getScDocShell()->GetModel(), 
getCellRangesBase() );
+    sal_Int32 nFlags = VALUE | DATETIME | STRING | FORMULA | HARDATTR | 
EDITATTR | FORMATTED;
+    ClearContents( nFlags, true );
+    // Fire the range change event
+    lcl_NotifyRangeChanges( getScDocShell()->GetModel(), getCellRangesBase() );
 }
 
 //helper ClearContent
-void
+void SAL_CALL
 // MS Excel VBA: Internal helper - clears contents with specified flags.
 // Status: internal helper
 ScVbaRange::ClearContents( sal_Int32 nFlags, bool bFireEvent )
@@ -5468,6 +5571,201 @@ ScVbaRange::MergeArea()
     return new ScVbaRange( mxParent, mxContext, mxRange );
 }
 
+// MS Excel VBA: Returns the range of precedent cells (cells referenced by 
formulas).
+// Status: implemented - parses formula strings for cell references
+uno::Reference< ooo::vba::excel::XRange > SAL_CALL
+ScVbaRange::getPrecedents()
+{
+    try
+    {
+        uno::Reference< sheet::XSheetCellRange > xSheetRange(mxRange, 
uno::UNO_QUERY_THROW);
+        uno::Reference< sheet::XSpreadsheet > 
xSheet(xSheetRange->getSpreadsheet(), uno::UNO_QUERY_THROW);
+        uno::Reference< sheet::XCellRangesQuery > xQuery(mxRange, 
uno::UNO_QUERY_THROW);
+
+        // Get all formula cells in the range
+        uno::Reference< sheet::XSheetCellRanges > xFormulaCells = 
xQuery->queryFormulaCells(
+            sheet::FormulaResult::VALUE | sheet::FormulaResult::STRING |
+            sheet::FormulaResult::ERROR);
+
+        if (!xFormulaCells.is())
+            throw script::BasicErrorException();
+
+        // Get cell addresses of formula cells
+        uno::Sequence< table::CellRangeAddress > formulaAddresses =
+            xFormulaCells->getRangeAddresses();
+
+        // Collect referenced cell addresses by parsing formulas
+        std::vector< table::CellRangeAddress > refAddresses;
+        ScDocShell* pDocSh = getScDocShell();
+        ScDocument* pDoc = pDocSh ? pDocSh->GetDocument() : nullptr;
+
+        for (sal_Int32 i = 0; i < formulaAddresses.getLength(); ++i)
+        {
+            const table::CellRangeAddress& addr = formulaAddresses[i];
+            uno::Reference< table::XCell > xCell(
+                xSheet->getCellByPosition(addr.StartColumn, addr.StartRow), 
uno::UNO_QUERY_THROW);
+            rtl::OUString sFormula = xCell->getFormula();
+
+            // Parse formula for cell references
+            if (pDoc)
+            {
+                ScRangeList aParsedRanges;
+                sal_uInt16 nFlags = 0;
+                formula::FormulaGrammar::AddressConvention eConv =
+                    formula::FormulaGrammar::CONV_OOO;
+                rtl::OUString sAddr = sFormula.copy(1); // skip leading '='
+                nFlags = aParsedRanges.Parse(sAddr, pDoc, SCA_VALID, eConv, 
addr.Sheet);
+
+                if (nFlags & SCA_VALID)
+                {
+                    for (ScRange* pRange = aParsedRanges.First(); pRange;
+                         pRange = aParsedRanges.Next())
+                    {
+                        table::CellRangeAddress refAddr;
+                        refAddr.Sheet = pRange->aStart.Tab();
+                        refAddr.StartColumn = pRange->aStart.Col();
+                        refAddr.StartRow = pRange->aStart.Row();
+                        refAddr.EndColumn = pRange->aEnd.Col();
+                        refAddr.EndRow = pRange->aEnd.Row();
+                        refAddresses.push_back(refAddr);
+                    }
+                }
+            }
+        }
+
+        if (refAddresses.empty())
+            throw script::BasicErrorException();
+
+        // Build union range from all referenced addresses
+        ScRangeList aUnionRanges;
+        for (const auto& addr : refAddresses)
+        {
+            ScRange aRange( static_cast<SCCOL>(addr.StartColumn), 
static_cast<SCROW>(addr.StartRow),
+                static_cast<SCTAB>(addr.Sheet),
+                static_cast<SCCOL>(addr.EndColumn), 
static_cast<SCROW>(addr.EndRow),
+                static_cast<SCTAB>(addr.Sheet));
+            aUnionRanges.Append(aRange);
+        }
+
+        if (aUnionRanges.Count() == 0)
+            throw script::BasicErrorException();
+
+        if (aUnionRanges.Count() == 1)
+        {
+            uno::Reference< table::XCellRange > xRange;
+            xRange.set(new ScCellRangeObj(pDocSh, *aUnionRanges.First()));
+            return new ScVbaRange(mxParent, mxContext, xRange);
+        }
+        else
+        {
+            uno::Reference< sheet::XSheetCellRangeContainer > xRanges;
+            xRanges.set(new ScCellRangesObj(pDocSh, aUnionRanges));
+            return new ScVbaRange(mxParent, mxContext, xRanges);
+        }
+    }
+    catch (uno::Exception&)
+    {
+        throw script::BasicErrorException();
+    }
+}
+
+// MS Excel VBA: Returns the range of dependent cells (cells that reference 
this range).
+// Status: implemented - scans all formula cells for references to this range
+uno::Reference< ooo::vba::excel::XRange > SAL_CALL
+ScVbaRange::getDependents()
+{
+    try
+    {
+        table::CellRangeAddress myAddr = lclGetRangeAddress(mxRange);
+        ScDocShell* pDocSh = getScDocShell();
+        ScDocument* pDoc = pDocSh ? pDocSh->GetDocument() : nullptr;
+        if (!pDoc)
+            throw script::BasicErrorException();
+
+        uno::Reference< sheet::XSheetCellRange > xSheetRange(mxRange, 
uno::UNO_QUERY_THROW);
+        uno::Reference< sheet::XSpreadsheet > 
xSheet(xSheetRange->getSpreadsheet(), uno::UNO_QUERY_THROW);
+
+        // Get all cells in the sheet
+        uno::Reference< sheet::XCellRangeAddressable > xAddr(xSheet, 
uno::UNO_QUERY_THROW);
+        table::CellRangeAddress sheetAddr = xAddr->getRangeAddress();
+        uno::Reference< table::XCellRange > xSheetCells(
+            xSheet->getCellRangeByPosition(0, 0,
+                sheetAddr.EndColumn, sheetAddr.EndRow), uno::UNO_QUERY_THROW);
+        uno::Reference< sheet::XCellRangesQuery > xQuery(xSheetCells, 
uno::UNO_QUERY_THROW);
+        uno::Reference< sheet::XSheetCellRanges > xFormulaCells = 
xQuery->queryFormulaCells(
+            sheet::FormulaResult::VALUE | sheet::FormulaResult::STRING |
+            sheet::FormulaResult::ERROR);
+
+        if (!xFormulaCells.is())
+            throw script::BasicErrorException();
+
+        uno::Sequence< table::CellRangeAddress > addrList = 
xFormulaCells->getRangeAddresses();
+
+        std::vector< table::CellRangeAddress > dependentRanges;
+        for (sal_Int32 i = 0; i < addrList.getLength(); ++i)
+        {
+            const table::CellRangeAddress& addr = addrList[i];
+            uno::Reference< table::XCell > xCell(
+                xSheet->getCellByPosition(addr.StartColumn, addr.StartRow), 
uno::UNO_QUERY_THROW);
+            rtl::OUString sFormula = xCell->getFormula();
+
+            // Check if formula references any cell in our range
+            ScRangeList aParsedRanges;
+            formula::FormulaGrammar::AddressConvention eConv =
+                formula::FormulaGrammar::CONV_OOO;
+            rtl::OUString sAddr = sFormula.copy(1);
+            aParsedRanges.Parse(sAddr, pDoc, SCA_VALID, eConv, addr.Sheet);
+
+            bool bFound = false;
+            for (ScRange* pRange = aParsedRanges.First(); pRange && !bFound;
+                 pRange = aParsedRanges.Next())
+            {
+                if (pRange->aStart.Tab() == myAddr.Sheet &&
+                    pRange->aStart.Col() >= myAddr.StartColumn &&
+                    pRange->aStart.Row() >= myAddr.StartRow &&
+                    pRange->aEnd.Col() <= myAddr.EndColumn &&
+                    pRange->aEnd.Row() <= myAddr.EndRow)
+                {
+                    bFound = true;
+                }
+            }
+
+            if (bFound)
+                dependentRanges.push_back(addr);
+        }
+
+        if (dependentRanges.empty())
+            throw script::BasicErrorException();
+
+        ScRangeList aUnionRanges;
+        for (const auto& addr : dependentRanges)
+        {
+            ScRange aRange(static_cast<SCCOL>(addr.StartColumn), 
static_cast<SCROW>(addr.StartRow),
+                static_cast<SCTAB>(addr.Sheet),
+                static_cast<SCCOL>(addr.EndColumn), 
static_cast<SCROW>(addr.EndRow),
+                static_cast<SCTAB>(addr.Sheet));
+            aUnionRanges.Append(aRange);
+        }
+
+        if (aUnionRanges.Count() == 1)
+        {
+            uno::Reference< table::XCellRange > xRange;
+            xRange.set(new ScCellRangeObj(pDocSh, *aUnionRanges.First()));
+            return new ScVbaRange(mxParent, mxContext, xRange);
+        }
+        else
+        {
+            uno::Reference< sheet::XSheetCellRangeContainer > xRanges;
+            xRanges.set(new ScCellRangesObj(pDocSh, aUnionRanges));
+            return new ScVbaRange(mxParent, mxContext, xRanges);
+        }
+    }
+    catch (uno::Exception&)
+    {
+        throw script::BasicErrorException();
+    }
+}
+
 // MS Excel VBA: Prints the range.
 // Status: implemented
 void SAL_CALL
@@ -5671,6 +5969,8 @@ ScVbaRange::Calculate(  )
        getWorksheet()->Calculate();
 }
 
+// MS Excel VBA: Clears the entire range.
+
 // MS Excel VBA: Returns a subrange at the specified row and column.
 // Status: implemented
 uno::Reference< excel::XRange > SAL_CALL
@@ -5689,10 +5989,7 @@ ScVbaRange::Item( const uno::Any& row, const uno::Any& 
column )
        }
        return Cells( row, column );
 }
-
-void
-// MS Excel VBA: Creates an outline for the range.
-// Status: stubbed - not fully implemented in Calc
+void SAL_CALL
 ScVbaRange::AutoOutline(  )
 {
        // #TODO #FIXME needs to check for summary row/col ( whatever they are )
diff --git a/main/sc/source/ui/vba/vbarange.hxx 
b/main/sc/source/ui/vba/vbarange.hxx
index 72d3997222..5820c8a9ad 100644
--- a/main/sc/source/ui/vba/vbarange.hxx
+++ b/main/sc/source/ui/vba/vbarange.hxx
@@ -248,6 +248,20 @@ public:
 // MS Excel VBA: Sets the value of the range.
 // Status: implemented
        virtual void   SAL_CALL setValue( const css::uno::Any& aValue );
+// MS Excel VBA: Gets the value of the range without type conversion (Value2).
+// Status: implemented
+// MS Excel VBA: Gets the value of the range without type conversion (Value2).
+// Status: implemented
+       virtual css::uno::Any SAL_CALL getValue2();
+       virtual void   SAL_CALL setValue2( const css::uno::Any& rValue );
+       virtual css::uno::Any SAL_CALL getAddIndent();
+       virtual void   SAL_CALL setAddIndent( const css::uno::Any& rAddIndent );
+// MS Excel VBA: Returns the range of precedent cells that the range depends 
on.
+// Status: implemented
+       virtual css::uno::Reference< ooo::vba::excel::XRange > SAL_CALL 
getPrecedents();
+// MS Excel VBA: Returns the range of dependent cells that depend on the range.
+// Status: implemented
+       virtual css::uno::Reference< ooo::vba::excel::XRange > SAL_CALL 
getDependents();
 // MS Excel VBA: Gets the formula of the range.
 // Status: implemented
        virtual css::uno::Any SAL_CALL getFormula();
diff --git a/main/sc/util/vbaobj.component b/main/sc/util/vbaobj.component
index 0531fb6deb..8f3aeacbf6 100644
--- a/main/sc/util/vbaobj.component
+++ b/main/sc/util/vbaobj.component
@@ -51,4 +51,10 @@
   <implementation name="SvVbaRange">
     <service name="ooo.vba.excel.Range"/>
   </implementation>
+  <implementation name="ScVbaFileSystemObject">
+    <service name="ooo.vba.FileSystemObject"/>
+  </implementation>
+  <implementation name="ScVbaDictionary">
+    <service name="ooo.vba.Scripting.Dictionary"/>
+  </implementation>
 </component>
diff --git a/main/udkapi/com/sun/star/uno/XInterface.idl 
b/main/udkapi/com/sun/star/uno/XInterface.idl
index 7523d7aa6d..518d737210 100644
--- a/main/udkapi/com/sun/star/uno/XInterface.idl
+++ b/main/udkapi/com/sun/star/uno/XInterface.idl
@@ -110,7 +110,7 @@ published interface XInterface
 
        
//-------------------------------------------------------------------------
 
-       // DocMerge from xml: method com::sun::star::uno::XInterface::release
+       /* DocMerge from xml: method com::sun::star::uno::XInterface::release */
        /** decreases the reference counter by one.
                <p>When the reference counter reaches 0, the object gets 
deleted.</p>
         <p>Calling release() on the object is often called releasing

Reply via email to