--- sc/source/core/tool/interpr4.cxx	2007-09-11 17:02:51.000000000 +0100
+++ sc/source/core/tool/interpr4.cxx	2007-09-11 16:59:02.000000000 +0100
@@ -41,10 +41,12 @@
 #include <sfx2/app.hxx>
 #include <sfx2/docfile.hxx>
 #include <sfx2/objsh.hxx>
+#include <sfx2/docfilt.hxx>
 #include <basic/sbmeth.hxx>
 #include <basic/sbmod.hxx>
 #include <basic/sbstar.hxx>
 #include <basic/sbx.hxx>
+#include <basic/sbuno.hxx>
 #include <svtools/zforlist.hxx>
 #include <tools/urlobj.hxx>
 #include <stdlib.h>
@@ -57,6 +59,7 @@
 #include <functional>
 
 #include <com/sun/star/table/XCellRange.hpp>
+#include <comphelper/processfactory.hxx>
 
 #include "interpre.hxx"
 #include "global.hxx"
@@ -2299,7 +2302,38 @@ void ScInterpreter::ScMissing()
 	PushTempToken( new ScMissingToken );
 }
 
-
+bool
+lcl_setVBARange( ScRange& aRange, ScDocument* pDok, SbxVariable* pPar )
+{
+	bool bOk = false;
+	try
+	{
+		uno::Reference< uno::XInterface > xVBARange;
+		uno::Reference< lang::XMultiComponentFactory > xSMgr( ::comphelper::getProcessServiceFactory(), uno::UNO_QUERY_THROW );
+		uno::Reference< beans::XPropertySet > xProps( xSMgr, uno::UNO_QUERY_THROW );
+		uno::Reference< uno::XComponentContext > xCtx( xProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DefaultContext" ))), uno::UNO_QUERY_THROW );
+		uno::Reference<table::XCellRange> xCellRange = ScCellRangeObj::CreateRangeFromDoc( pDok, aRange );
+		// hmm probably better not to have to include the vba generated headers
+		// here, but... if they ever become always available certainly the
+		// line below is more coder friendly
+		//xRange = org::openoffice::excel::Range::createRangeFromXCellRange( xCtx , uno::Reference< org::openoffice::vba::XHelperInterface >(), xCellRange );	
+		uno::Sequence< uno::Any > aArgs(2);
+		aArgs[0] = uno::Any( uno::Reference< uno::XInterface >() ); // dummy parent
+		aArgs[1] = uno::Any( xCellRange );
+		xVBARange = xSMgr->createInstanceWithArgumentsAndContext( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("org.openoffice.excel.Range") ), aArgs, xCtx  );
+		if ( xVBARange.is() )
+		{
+			String sDummy(RTL_CONSTASCII_USTRINGPARAM("A-Range") );
+			SbxObjectRef aObj = GetSbUnoObject( sDummy, uno::Any( xVBARange ) );
+			SetSbUnoObjectDfltPropName( aObj );
+			bOk = pPar->PutObject( aObj );
+		}
+	}
+	catch( uno::Exception& )
+	{
+	}
+	return bOk;
+}
 void ScInterpreter::ScMacro()
 {
 	SbxBase::ResetError();
@@ -2337,6 +2371,7 @@ void ScInterpreter::ScMacro()
 
 	SbMethod* pMethod = (SbMethod*)pVar;
 	SbModule* pModule = pMethod->GetModule();
+	bool bUseVBAObjects = pModule->IsVBACompat();
 	SbxObject* pObject = pModule->GetParent();
 	DBG_ASSERT(pObject->IsA(TYPE(StarBASIC)), "Kein Basic gefunden!");
 	String aMacroStr = pObject->GetName();
@@ -2346,7 +2381,13 @@ void ScInterpreter::ScMacro()
 	aMacroStr += pMethod->GetName();
 	String aBasicStr;
 	if (pObject->GetParent())
+	{
 		aBasicStr = pObject->GetParent()->GetName();	// Dokumentenbasic
+		const SfxFilter* pFilter = NULL;
+		SfxMedium* pMedium = pDok->GetDocumentShell()->GetMedium();
+		if ( pMedium )
+			pFilter = pMedium->GetFilter();
+	}
 	else
 		aBasicStr = SFX_APP()->GetName();				// Applikationsbasic
 
@@ -2370,7 +2411,13 @@ void ScInterpreter::ScMacro()
 			{
 				ScAddress aAdr;
 				PopSingleRef( aAdr );
-				bOk = SetSbxVariable( pPar, aAdr );
+				if ( bUseVBAObjects )
+				{
+					ScRange aRange( aAdr );
+					bOk = lcl_setVBARange( aRange, pDok, pPar );
+				}
+				else
+					bOk = SetSbxVariable( pPar, aAdr );
 			}
 			break;
 			case svDoubleRef:
@@ -2389,24 +2436,32 @@ void ScInterpreter::ScMacro()
 				}
 				else
 				{
-					SbxDimArrayRef refArray = new SbxDimArray;
-					refArray->AddDim32( 1, nRow2 - nRow1 + 1 );
-					refArray->AddDim32( 1, nCol2 - nCol1 + 1 );
-					ScAddress aAdr( nCol1, nRow1, nTab1 );
-					for( SCROW nRow = nRow1; bOk && nRow <= nRow2; nRow++ )
+					if ( bUseVBAObjects )
 					{
-						aAdr.SetRow( nRow );
-						INT32 nIdx[ 2 ];
-						nIdx[ 0 ] = nRow-nRow1+1;
-						for( SCCOL nCol = nCol1; bOk && nCol <= nCol2; nCol++ )
-						{
-							aAdr.SetCol( nCol );
-							nIdx[ 1 ] = nCol-nCol1+1;
-							SbxVariable* p = refArray->Get32( nIdx );
-							bOk = SetSbxVariable( p, aAdr );
+						ScRange aRange( nCol1, nRow1, nTab1, nCol2, nRow2, nTab2 );
+						bOk = lcl_setVBARange( aRange, pDok, pPar );
+					}
+					else
+					{
+						SbxDimArrayRef refArray = new SbxDimArray;
+						refArray->AddDim32( 1, nRow2 - nRow1 + 1 );
+						refArray->AddDim32( 1, nCol2 - nCol1 + 1 );
+						ScAddress aAdr( nCol1, nRow1, nTab1 );
+						for( SCROW nRow = nRow1; bOk && nRow <= nRow2; nRow++ )
+						{
+							aAdr.SetRow( nRow );
+							INT32 nIdx[ 2 ];
+							nIdx[ 0 ] = nRow-nRow1+1;
+							for( SCCOL nCol = nCol1; bOk && nCol <= nCol2; nCol++ )
+							{
+								aAdr.SetCol( nCol );
+								nIdx[ 1 ] = nCol-nCol1+1;
+								SbxVariable* p = refArray->Get32( nIdx );
+								bOk = SetSbxVariable( p, aAdr );
+							}
 						}
+						pPar->PutObject( refArray );
 					}
-					pPar->PutObject( refArray );
 				}
 			}
 			break;
--- basic/inc/basic/sbmod.hxx	2007-09-11 10:28:53.000000000 +0100
+++ basic/inc/basic/sbmod.hxx	2007-09-11 12:45:24.000000000 +0100
@@ -76,6 +76,7 @@ protected:
 	SbiBreakpoints*	pBreaks;			// Breakpoints
 	SbClassData*	pClassData;
 	bool bThisWorkBook; // Should really subclass the module
+	bool mbVBACompat;
 
 	void			StartDefinitions();
 	SbMethod*		GetMethod( const String&, SbxDataType );
@@ -136,6 +137,7 @@ public:
 	BOOL LoadBinaryData( SvStream& );
 	BOOL ExceedsLegacyModuleSize();
 	void fixUpMethodStart( bool bCvtToLegacy, SbiImage* pImg = NULL ) const;
+        bool IsVBACompat() { return mbVBACompat; }
 };
 
 #ifndef __SB_SBMODULEREF_HXX
--- basic/source/classes/sbxmod.cxx	2007-09-11 10:28:53.000000000 +0100
+++ basic/source/classes/sbxmod.cxx	2007-09-11 13:59:11.000000000 +0100
@@ -239,7 +239,7 @@ extern "C" int CDECL compare_strings( co
 
 SbModule::SbModule( const String& rName )
 		 : SbxObject( String( RTL_CONSTASCII_USTRINGPARAM("StarBASICModule") ) ),
-		   pImage( NULL ), pBreaks( NULL ), pClassData( NULL ), bThisWorkBook( false )
+		   pImage( NULL ), pBreaks( NULL ), pClassData( NULL ), bThisWorkBook( false ), mbVBACompat( false )
 {
 	SetName( rName );
 	SetFlag( SBX_EXTSEARCH | SBX_GBLSEARCH );
@@ -553,8 +554,9 @@ void SbModule::SetSource32( const ::rtl:
 				if( eCurTok == OPTION )
 				{
 					eCurTok = aTok.Next();
+					mbVBACompat = ( eCurTok == VBASUPPORT ) && ( aTok.Next() == NUMBER ) && ( aTok.GetDbl()== 1 );
 					if( eCurTok == COMPATIBLE 
-					|| ( ( eCurTok == VBASUPPORT ) && ( aTok.Next() == NUMBER ) && ( aTok.GetDbl()== 1 ) ) )
+					|| mbVBACompat )
 						aTok.SetCompatible( true );
 				}
 			}
--- basic/source/classes/sbunoobj.cxx	2007-09-11 14:56:06.000000000 +0100
+++ basic/source/classes/sbunoobj.cxx	2007-09-11 10:28:44.000000000 +0100
@@ -170,6 +170,21 @@ SbxVariable* getDefaultProp( SbxVariable
 	return pDefaultProp;
 }
 
+void SetSbUnoObjectDfltPropName( SbxObject* pObj )
+{
+	SbUnoObject* pUnoObj = PTR_CAST(SbUnoObject,(SbxObject*) pObj);
+	if ( pUnoObj )
+	{
+		String sDfltPropName;
+		
+		if ( SbUnoObject::getDefaultPropName( pUnoObj, sDfltPropName ) )
+		{
+			OSL_TRACE("SetSbUnoObjectDfltPropName setting dflt prop for %s", rtl::OUStringToOString( pObj->GetName(), RTL_TEXTENCODING_UTF8 ).getStr() );
+			pUnoObj->SetDfltProperty( sDfltPropName );
+		}
+	}
+}
+
 Reference< XComponentContext > getComponentContext_Impl( void )
 {
     static Reference< XComponentContext > xContext;
--- basic/inc/basic/sbuno.hxx	2007-04-11 13:53:10.000000000 +0100
+++ basic/inc/basic/sbuno.hxx	2007-09-06 13:26:48.000000000 +0100
@@ -48,6 +48,7 @@ SbxObjectRef GetSbUnoObject( const Strin
 
 // Force creation of all properties for debugging
 void createAllObjectProperties( SbxObject* pObj );
+void SetSbUnoObjectDfltPropName( SbxObject* pObj );
 
 #endif
 
