ooo-build r14426 - trunk/patches/vba/native-export



Author: noelpwer
Date: Wed Oct 29 15:27:45 2008
New Revision: 14426
URL: http://svn.gnome.org/viewvc/ooo-build?rev=14426&view=rev

Log:
native export for useform/object-module ( & associated data )


Added:
   trunk/patches/vba/native-export/
   trunk/patches/vba/native-export/ObjectModule.diff
   trunk/patches/vba/native-export/basic-ide-module-object-name-combile.diff
   trunk/patches/vba/native-export/vba-basic-macrochoose-dialog.diff
   trunk/patches/vba/native-export/vba-compatible-mode-uno.diff
   trunk/patches/vba/native-export/vba-userform-geometry-tweak.diff
   trunk/patches/vba/native-export/vbainfo-import-export-support.diff

Added: trunk/patches/vba/native-export/ObjectModule.diff
==============================================================================
--- (empty file)
+++ trunk/patches/vba/native-export/ObjectModule.diff	Wed Oct 29 15:27:45 2008
@@ -0,0 +1,2330 @@
+diff --git basctl/source/basicide/basides1.cxx basctl/source/basicide/basides1.cxx
+index aed5958..3d79067 100644
+--- basctl/source/basicide/basides1.cxx
++++ basctl/source/basicide/basides1.cxx
+@@ -1201,10 +1201,16 @@ IDEBaseWindow* BasicIDEShell::FindWindow
+                 // return any non-suspended window
+                 return pWin;
+             }
+-            else if ( pWin->IsDocument( rDocument ) && pWin->GetLibName() == rLibName && pWin->GetName() == rName &&
++            else if ( pWin->IsDocument( rDocument ) )
++            {
++                OSL_TRACE("FindWindow pWin->GetLibName() %s rLibName %s",
++			rtl::OUStringToOString( pWin->GetLibName(), RTL_TEXTENCODING_UTF8 ).getStr(),
++			rtl::OUStringToOString( rLibName, RTL_TEXTENCODING_UTF8 ).getStr() );
++                OSL_TRACE("pWin->pWin->IsA( TYPE( ModulWindow ) %d && nType %d = BASICIDE_TYPE_MODULE %d", pWin->IsA( TYPE( ModulWindow ) ), nType, BASICIDE_TYPE_MODULE );
++                OSL_TRACE("pWin->pWin->IsA( TYPE( DialogWindow ) %d && nType %d = BASICIDE_TYPE_DIALOG %d", pWin->IsA( TYPE( DialogWindow ) ), nType, BASICIDE_TYPE_DIALOG );
++		if (  pWin->GetLibName() == rLibName && pWin->GetName() == rName &&
+                       ( ( pWin->IsA( TYPE( ModulWindow ) )  && nType == BASICIDE_TYPE_MODULE ) ||
+                         ( pWin->IsA( TYPE( DialogWindow ) ) && nType == BASICIDE_TYPE_DIALOG ) ) )
+-            {
+                 return pWin;
+             }
+         }
+diff --git basctl/source/basicide/basides2.cxx basctl/source/basicide/basides2.cxx
+index 76dcea0..90cec19 100644
+--- basctl/source/basicide/basides2.cxx
++++ basctl/source/basicide/basides2.cxx
+@@ -251,9 +251,12 @@ ModulWindow* BasicIDEShell::CreateBasWin
+ 
+         if ( bSuccess )
+         {
+-			// new module window
+-			pWin = new ModulWindow( pModulLayout, rDocument, aLibName, aModName, aModule );
+-			nKey = InsertWindowInTable( pWin );
++			pWin = FindBasWin( rDocument, aLibName, aModName, FALSE, TRUE );
++            if( !pWin )
++			{    // new module window
++			    pWin = new ModulWindow( pModulLayout, rDocument, aLibName, aModName, aModule );
++			    nKey = InsertWindowInTable( pWin );
++            }
+         }
+ 	}
+ 	else
+@@ -268,7 +271,8 @@ ModulWindow* BasicIDEShell::CreateBasWin
+ 		}
+ 		DBG_ASSERT( nKey, "CreateBasWin: Kein Key- Fenster nicht gefunden!" );
+ 	}
+-	pTabBar->InsertPage( (USHORT)nKey, aModName );
++    if( nKey )
++	    pTabBar->InsertPage( (USHORT)nKey, aModName );
+ 	pTabBar->Sort();
+ 	pWin->GrabScrollBars( &aHScrollBar, &aVScrollBar );
+ 	if ( !pCurWin )
+diff --git basctl/source/basicide/basidesh.cxx basctl/source/basicide/basidesh.cxx
+index 03459cc..d921d99 100644
+--- basctl/source/basicide/basidesh.cxx
++++ basctl/source/basicide/basidesh.cxx
+@@ -80,6 +80,9 @@
+ #include <com/sun/star/script/XLibraryContainer.hpp>
+ #include <com/sun/star/script/XLibraryContainerPassword.hpp>
+ #include <com/sun/star/container/XNameContainer.hpp>
++#include <com/sun/star/container/XContainer.hpp>
++#include <com/sun/star/container/XContainerListener.hpp>
++#include <com/sun/star/script/XLibraryContainer.hpp>
+ 
+ #include <svx/xmlsecctrl.hxx>
+ 
+@@ -87,6 +90,71 @@ using namespace ::com::sun::star::uno;
+ using namespace ::com::sun::star;
+ using ::rtl::OUString;
+ 
++static const rtl::OUString sStandardLibName(  rtl::OUString::createFromAscii("Standard") );
++
++typedef ::cppu::WeakImplHelper1< container::XContainerListener > ContainerListenerBASE;
++
++class ContainerListenerImpl : public ContainerListenerBASE
++{
++    BasicIDEShell* mpShell;
++public:
++
++    ContainerListenerImpl( BasicIDEShell* pShell ) : mpShell( pShell ) {}
++
++    ~ContainerListenerImpl() 
++    {
++    }
++
++    void addContainerListener( const ScriptDocument& rScriptDocument )
++    {
++        uno::Reference< container::XContainer > xContainer( rScriptDocument.getLibrary( E_SCRIPTS, sStandardLibName, FALSE ), uno::UNO_QUERY );
++        if ( rScriptDocument.isDocument() && xContainer.is() )
++        {
++            uno::Reference< container::XContainerListener > xContainerListener( this );
++            try
++            {
++                xContainer->addContainerListener( xContainerListener );
++            }
++            catch( uno::Exception& ) {}
++        }
++    }
++    void removeContainerListener( const ScriptDocument& rScriptDocument )
++    {
++        uno::Reference< container::XContainer > xContainer( rScriptDocument.getLibrary( E_SCRIPTS, sStandardLibName, FALSE ), uno::UNO_QUERY );
++        if ( rScriptDocument.isDocument(), xContainer.is() )
++        {
++            uno::Reference< container::XContainerListener > xContainerListener( this );
++            try
++            {
++               xContainer->removeContainerListener( xContainerListener );
++            }
++            catch( uno::Exception& ) {}
++        }
++    }
++
++    // XEventListener
++    virtual void SAL_CALL disposing( const lang::EventObject& ) throw( uno::RuntimeException ) {}
++
++    // XContainerListener
++    virtual void SAL_CALL elementInserted( const container::ContainerEvent& Event ) throw( uno::RuntimeException )
++    {
++        rtl::OUString sModuleName;
++        if( mpShell && ( Event.Accessor >>= sModuleName ) )
++            mpShell->FindBasWin( mpShell->m_aCurDocument, sStandardLibName, sModuleName, TRUE, FALSE );
++    }
++    virtual void SAL_CALL elementReplaced( const container::ContainerEvent& ) throw( com::sun::star::uno::RuntimeException ) { }
++    virtual void SAL_CALL elementRemoved( const container::ContainerEvent& Event ) throw( com::sun::star::uno::RuntimeException )
++    {
++        rtl::OUString sModuleName;
++        if( mpShell  && ( Event.Accessor >>= sModuleName ) )
++        {
++            IDEBaseWindow* pWin = mpShell->FindWindow( mpShell->m_aCurDocument, sStandardLibName, sModuleName, BASICIDE_TYPE_MODULE, TRUE );
++            if( pWin )
++                mpShell->RemoveWindow( pWin, FALSE, TRUE );
++        }
++    }
++
++};
+ 
+ TYPEINIT1( BasicIDEShell, SfxViewShell );
+ 
+@@ -124,6 +192,7 @@ BasicIDEShell::BasicIDEShell( SfxViewFra
+         m_bAppBasicModified( FALSE ),
+         m_aNotifier( *this )
+ {
++    m_xLibListener = new ContainerListenerImpl( this );
+ 	Init();
+     GnBasicIDEShellCount++;
+ }
+@@ -215,6 +284,12 @@ __EXPORT BasicIDEShell::~BasicIDEShell()
+ 	delete pTabBar;
+ 	delete pObjectCatalog;
+ 	DestroyModulWindowLayout();
++
++        ContainerListenerImpl* pListener = dynamic_cast< ContainerListenerImpl* >( m_xLibListener.get() );
++        // Destroy all ContainerListeners for Basic Container.
++        if ( pListener )
++            pListener->removeContainerListener( m_aCurDocument );
++    
+ 	// MI: Das gab einen GPF im SDT beim Schliessen da dann der ViewFrame die
+ 	// ObjSh loslaesst. Es wusste auch keiner mehr wozu das gut war.
+ 	// GetViewFrame()->GetObjectShell()->Broadcast( SfxSimpleHint( SFX_HINT_DYING ) );
+@@ -935,7 +1010,15 @@ void BasicIDEShell::SetCurLib( const Scr
+ {
+     if ( !bCheck || ( rDocument != m_aCurDocument || aLibName != m_aCurLibName ) )
+     {
++        ContainerListenerImpl* pListener = dynamic_cast< ContainerListenerImpl* >( m_xLibListener.get() );
++        if ( pListener )
++        	pListener->removeContainerListener( m_aCurDocument );
++
+         m_aCurDocument = rDocument;
++
++        if ( pListener )
++            pListener->addContainerListener( m_aCurDocument );
++
+         m_aCurLibName = aLibName;
+         if ( bUpdateWindows )
+             UpdateWindows();
+diff --git basctl/source/inc/basidesh.hxx basctl/source/inc/basidesh.hxx
+index 6b3690c..3919bd9 100644
+--- basctl/source/inc/basidesh.hxx
++++ basctl/source/inc/basidesh.hxx
+@@ -49,6 +49,7 @@
+ #include <com/sun/star/io/XInputStreamProvider.hpp>
+ #endif
+ 
++#include <com/sun/star/container/XContainerListener.hpp>
+ 
+ //----------------------------------------------------------------------------
+ 
+@@ -107,6 +108,8 @@ friend bool BasicIDE::RemoveDialog( cons
+     BOOL                m_bAppBasicModified;
+     ::basctl::DocumentEventNotifier
+                         m_aNotifier;
++friend class ContainerListenerImpl;
++    ::com::sun::star::uno::Reference< ::com::sun::star::container::XContainerListener > m_xLibListener;
+ 
+ #if _SOLAR__PRIVATE
+ 	void				Init();
+diff --git basic/inc/basic/sbmod.hxx basic/inc/basic/sbmod.hxx
+index 122a664..e676a49 100644
+--- basic/inc/basic/sbmod.hxx
++++ basic/inc/basic/sbmod.hxx
+@@ -37,7 +37,7 @@
+ #ifndef _RTL_USTRING_HXX
+ #include <rtl/ustring.hxx>
+ #endif
+-
++#include <com/sun/star/script/ModuleType.hpp>
+ class SbMethod;
+ class SbProperty;
+ class SbiRuntime;
+@@ -67,6 +67,9 @@ protected:
+ 	SbiBreakpoints*	pBreaks;			// Breakpoints
+ 	SbClassData*	pClassData;
+ 	bool mbVBACompat;
++	INT32 mnType; 
++	SbxObjectRef pDocObject; // an impl object ( used by Document Modules )
++	bool 	bIsProxyModule;
+ 
+ 	void			StartDefinitions();
+ 	SbMethod*		GetMethod( const String&, SbxDataType );
+@@ -91,7 +94,7 @@ protected:
+ public:
+ 	SBX_DECL_PERSIST_NODATA(SBXCR_SBX,SBXID_BASICMOD,2);
+ 	TYPEINFO();
+-					SbModule( const String& );
++					SbModule( const String&, bool bCompat = false );
+ 	virtual void	SetParent( SbxObject* );
+ 	virtual void 	Clear();
+ 
+@@ -127,8 +130,12 @@ public:
+ 	BOOL LoadBinaryData( SvStream& );
+ 	BOOL ExceedsLegacyModuleSize();
+ 	void fixUpMethodStart( bool bCvtToLegacy, SbiImage* pImg = NULL ) const;
+-        bool IsVBACompat() { return mbVBACompat; }
+         bool HasExeCode();
++        bool IsVBACompat();
++        void SetVBACompat( bool bCompat );
++        INT32 GetModuleType() { return mnType; }
++        void SetModuleType( INT32 nType ) { mnType = nType; }
++	bool GetIsProxyModule() { return bIsProxyModule; }
+ };
+ 
+ #ifndef __SB_SBMODULEREF_HXX
+diff --git basic/inc/basic/sbobjmod.hxx basic/inc/basic/sbobjmod.hxx
+new file mode 100644
+index 0000000..cb581c1
+--- /dev/null
++++ basic/inc/basic/sbobjmod.hxx
+@@ -0,0 +1,66 @@
++/*************************************************************************
++ *
++ *  OpenOffice.org - a multi-platform office productivity suite
++ *
++ *  $RCSfile: sbobjmod.hxx,v $
++ *
++ *  $Revision: 1.4 $
++ *
++ *  last change: $Author:  $ $Date: 2007/08/27 16:31:39 $
++ *
++ *  The Contents of this file are made available subject to
++ *  the terms of GNU Lesser General Public License Version 2.1.
++ *
++ *
++ *    GNU Lesser General Public License Version 2.1
++ *    =============================================
++ *    Copyright 2005 by Sun Microsystems, Inc.
++ *    901 San Antonio Road, Palo Alto, CA 94303, USA
++ *
++ *    This library is free software; you can redistribute it and/or
++ *    modify it under the terms of the GNU Lesser General Public
++ *    License version 2.1, as published by the Free Software Foundation.
++ *
++ *    This library is distributed in the hope that it will be useful,
++ *    but WITHOUT ANY WARRANTY; without even the implied warranty of
++ *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
++ *    Lesser General Public License for more details.
++ *
++ *    You should have received a copy of the GNU Lesser General Public
++ *    License along with this library; if not, write to the Free Software
++ *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
++ *    MA  02111-1307  USA
++ *
++ ************************************************************************/
++
++#ifndef _SB_OBJMOD_HXX
++#define _SB_OBJMOD_HXX
++
++#include <basic/sbmod.hxx>
++#include <basic/sbstar.hxx>
++#include <com/sun/star/script/ModuleInfo.hpp>
++#include <com/sun/star/lang/XEventListener.hpp>
++#include <com/sun/star/awt/XDialog.hpp>
++
++namespace css = ::com::sun::star;
++
++// Basic-Module for excel object.
++
++class SbObjModule : public SbModule
++{
++public:
++    TYPEINFO();
++    SbObjModule( const com::sun::star::script::ModuleInfo& mInfo, bool bIsVbaCompatible );
++    virtual SbxVariable* Find( const XubString& rName, SbxClassType t );
++    SbxVariable* GetObject();
++    void SetUnoObject( const com::sun::star::uno::Any& aObj )throw ( com::sun::star::uno::RuntimeException ) ;
++};
++
++#ifndef __SB_SBOBJMODULEREF_HXX
++#define __SB_SBOBJMODULEREF_HXX
++
++SV_DECL_IMPL_REF(SbObjModule);
++
++#endif
++#endif
++
+diff --git basic/inc/basic/sbstar.hxx basic/inc/basic/sbstar.hxx
+index ebd10ae..1f20e9d 100644
+--- basic/inc/basic/sbstar.hxx
++++ basic/inc/basic/sbstar.hxx
+@@ -40,6 +40,7 @@
+ 
+ #include <basic/sbdef.hxx>
+ #include <basic/sberrors.hxx>
++#include <com/sun/star/script/ModuleInfo.hpp>
+ 
+ class SbModule;                     // fertiges Modul
+ class SbiInstance;                  // Laufzeit-Instanz
+@@ -71,6 +72,7 @@ class StarBASIC : public SbxObject
+ 	BOOL			bNoRtl;				// TRUE: RTL nicht durchsuchen
+ 	BOOL			bBreak;				// TRUE: Break, sonst Step
+ 	BOOL			bDocBasic;
++    BOOL            bVBAEnabled;
+ 	BasicLibInfo*	pLibInfo;			// Infoblock fuer Basic-Manager
+ 	SbLanguageMode	eLanguageMode;		// LanguageMode des Basic-Objekts
+ protected:
+@@ -113,7 +115,8 @@ public:
+ 
+ 	// Compiler-Interface
+ 	SbModule*   	MakeModule( const String& rName, const String& rSrc );
+-    SbModule*   	MakeModule32( const String& rName, const ::rtl::OUString& rSrc );
++    SbModule*       MakeModule32( const String& rName, const ::rtl::OUString& rSrc );
++    SbModule*       MakeModule32( const com::sun::star::script::ModuleInfo& mInfo, const ::rtl::OUString& rSrc );
+ 	BOOL			Compile( SbModule* );
+ 	BOOL 			Disassemble( SbModule*, String& rText );
+ 	static void 	Stop();
+@@ -185,6 +188,8 @@ public:
+ 					( const String& rName, USHORT& rStatus );
+ 	static SbMethod* GetActiveMethod( USHORT nLevel = 0 );
+ 	static SbModule* GetActiveModule();
++    void SetVBAEnabled( BOOL bEnabled );
++    BOOL isVBAEnabled();
+ 
+ 	// #60175 TRUE: SFX-Resource wird bei Basic-Fehlern nicht angezogen
+ 	static void StaticSuppressSfxResource( BOOL bSuppress );
+diff --git basic/source/basmgr/basmgr.cxx basic/source/basmgr/basmgr.cxx
+index 73eb4cb..864a941 100644
+--- basic/source/basmgr/basmgr.cxx
++++ basic/source/basmgr/basmgr.cxx
+@@ -44,6 +44,7 @@
+ #include <tools/debug.hxx>
+ #include <tools/diagnose_ex.h>
+ #include <basic/sbmod.hxx>
++#include <basic/sbobjmod.hxx>
+ 
+ #include <basic/sbuno.hxx>
+ #include <basic/basmgr.hxx>
+@@ -67,6 +68,9 @@
+ #include <com/sun/star/script/XStarBasicDialogInfo.hpp>
+ #include <com/sun/star/script/XStarBasicLibraryInfo.hpp>
+ #include <com/sun/star/script/XLibraryContainerPassword.hpp>
++#include <com/sun/star/script/ModuleInfo.hpp>
++#include <com/sun/star/script/ModuleType.hpp>
++#include <com/sun/star/script/XBasicLibraryInfo.hpp>
+ 
+ #include <cppuhelper/implbase1.hxx>
+ 
+@@ -236,6 +240,11 @@ void BasMgrContainerListenerImpl::addLib
+ 
+ 	StarBASIC* pLib = pMgr->GetLib( aLibName );
+ 	DBG_ASSERT( pLib, "BasMgrContainerListenerImpl::addLibraryModulesImpl: Unknown lib!");
++	Reference<  XBasicLibraryInfo > xLibInfo( xLibNameAccess, UNO_QUERY );
++	if ( xLibInfo.is() && xLibInfo->getVBACompatMode() )
++		pLib->SetVBAEnabled( true );
++	
++	OSL_TRACE("addLibraryModulesImpl libname %s, xLibInfo %d", rtl::OUStringToOString( aLibName, RTL_TEXTENCODING_UTF8 ).getStr(), xLibInfo.is() );
+ 	if( pLib )
+ 	{
+ 		const ::rtl::OUString* pNames = aModuleNames.getConstArray();
+@@ -245,7 +254,15 @@ void BasMgrContainerListenerImpl::addLib
+ 			Any aElement = xLibNameAccess->getByName( aModuleName );
+ 			::rtl::OUString aMod;
+ 			aElement >>= aMod;
+-			pLib->MakeModule32( aModuleName, aMod );
++
++			if ( xLibInfo.is() && xLibInfo->getVBACompatMode() )
++			{
++            	ModuleInfo mInfo = xLibInfo->getModuleInfo( pNames[ j ] );
++                OSL_TRACE("#addLibraryModulesImpl - aMod");
++                pLib->MakeModule32( mInfo, aMod );
++            }
++            else
++			    pLib->MakeModule32( aModuleName, aMod );
+ 		}
+ 	}
+ 
+@@ -274,6 +291,7 @@ void SAL_CALL BasMgrContainerListenerImp
+ 	Event.Accessor >>= aName;
+ 
+     mpMgr->mpImpl->mbModifiedByLibraryContainer = sal_True;
++	Reference<  XBasicLibraryInfo > xLibInfo( Event.Source, UNO_QUERY );
+ 
+ 	if( bLibContainer )
+ 	{
+@@ -282,8 +300,6 @@ void SAL_CALL BasMgrContainerListenerImp
+ 	}
+ 	else
+ 	{
+-		::rtl::OUString aMod;
+-		Event.Element >>= aMod;
+ 
+ 		StarBASIC* pLib = mpMgr->GetLib( maLibName );
+ 		DBG_ASSERT( pLib, "BasMgrContainerListenerImpl::elementInserted: Unknown lib!");
+@@ -292,7 +308,17 @@ void SAL_CALL BasMgrContainerListenerImp
+     		SbModule* pMod = pLib->FindModule( aName );
+             if( !pMod )
+             {
+-			    pLib->MakeModule32( aName, aMod );
++        		::rtl::OUString aMod;
++        		Event.Element >>= aMod;
++                if ( xLibInfo.is() && xLibInfo->getVBACompatMode() )
++                {
++                    ModuleInfo mInfo = xLibInfo->getModuleInfo( aName );
++                    pLib->MakeModule32( mInfo, aMod );
++                }
++                else
++                {
++			        pLib->MakeModule32( aName, aMod );
++                }
+ 			    pLib->SetModified( FALSE );
+             }
+ 		}
+@@ -316,15 +342,26 @@ void SAL_CALL BasMgrContainerListenerImp
+     DBG_ASSERT( !bLibContainer, "library container fired elementReplaced()");
+ 
+ 	StarBASIC* pLib = mpMgr->GetLib( maLibName );
++    
+ 	if( pLib )
+ 	{
+-		SbModule* pMod = pLib->FindModule( aName );
++	    SbModule* pMod = pLib->FindModule( aName );
+ 		::rtl::OUString aMod;
+-		Event.Element >>= aMod;
++        Event.Element >>= aMod;
++
+ 		if( pMod )
+ 			pMod->SetSource32( aMod );
+-		else
+-			pLib->MakeModule32( aName, aMod );
++        else
++        {
++			Reference<  XBasicLibraryInfo > xLibInfo( Event.Source, UNO_QUERY );
++			if (  xLibInfo.is() && xLibInfo->getVBACompatMode() )
++ 			{
++                ModuleInfo mInfo = xLibInfo->getModuleInfo( aName );
++				pLib->MakeModule32( mInfo, aMod );
++            }
++            else
++                pLib->MakeModule32( aName, aMod );
++        }
+ 
+ 		pLib->SetModified( FALSE );
+ 	}
+diff --git basic/source/classes/sb.cxx basic/source/classes/sb.cxx
+index f65c6ca..ac067de 100644
+--- basic/source/classes/sb.cxx
++++ basic/source/classes/sb.cxx
+@@ -52,12 +52,17 @@
+ #include "disas.hxx"
+ #include "runtime.hxx"
+ #include <basic/sbuno.hxx>
++#include <basic/sbobjmod.hxx>
+ #include "stdobj.hxx"
+ #include "filefmt.hxx"
+ #include "sb.hrc"
+ #include <basrid.hxx>
+ #include <vos/mutex.hxx>
+ 
++#include <com/sun/star/script/ModuleType.hpp>
++#include <com/sun/star/script/ModuleInfo.hpp>
++using namespace ::com::sun::star::script;
++
+ // #pragma SW_SEGMENT_CLASS( SBASIC, SBASIC_CODE )
+ 
+ SV_IMPL_VARARR(SbTextPortions,SbTextPortion)
+@@ -249,6 +254,8 @@ SbxObject* SbiFactory::CreateObject( con
+ 	else
+ 	if( rClass.EqualsIgnoreCaseAscii( "Collection" ) )
+ 	{
++			// Only variables qualified by the Module Name e.g. Sheet1.foo
++			// should work for Documant && Class type Modules
+ 		String aCollectionName( RTL_CONSTASCII_USTRINGPARAM("Collection") );
+ 		return new BasicCollection( aCollectionName );
+ 	}
+@@ -446,6 +453,7 @@ SbClassModuleObject::SbClassModuleObject
+ 			}
+ 		}
+ 	}
++	SetModuleType( com::sun::star::script::ModuleType::Class );
+ }
+ 
+ SbClassModuleObject::~SbClassModuleObject()
+@@ -581,6 +589,7 @@ StarBASIC::StarBASIC( StarBASIC* p, BOOL
+ 	SetParent( p );
+ 	pLibInfo = NULL;
+ 	bNoRtl = bBreak = FALSE;
++    bVBAEnabled = FALSE;
+ 	pModules = new SbxArray;
+ 
+ 	if( !GetSbData()->nInst++ )
+@@ -683,12 +692,37 @@ SbModule* StarBASIC::MakeModule( const S
+ 
+ SbModule* StarBASIC::MakeModule32( const String& rName, const ::rtl::OUString& rSrc )
+ {
+-	SbModule* p = new SbModule( rName );
++    ModuleInfo mInfo;
++    mInfo.ModuleType = ModuleType::Normal;
++    mInfo.ModuleName = rName;
++    return MakeModule32(  mInfo, rSrc );
++}
++SbModule* StarBASIC::MakeModule32( const ModuleInfo& mInfo, const ::rtl::OUString& rSrc )
++{
++    
++    OSL_TRACE("create module %s type mInfo %d", rtl::OUStringToOString( mInfo.ModuleName, RTL_TEXTENCODING_UTF8 ).getStr(), mInfo.ModuleType );
++    SbModule* p = NULL;
++    switch ( mInfo.ModuleType )
++    {
++        case ModuleType::Document:
++            // In theory we should be able to create Object modules
++            // in ordinary basic ( in vba mode thought these are create
++            // by the application/basic and not by the user )
++            p = new SbObjModule( mInfo, isVBAEnabled() );
++            break;
++        case ModuleType::Class:
++            p = new SbModule( mInfo.ModuleName, isVBAEnabled() );
++			p->SetModuleType( com::sun::star::script::ModuleType::Class );	
++	    break;
++        default:
++            p = new SbModule( mInfo.ModuleName, isVBAEnabled() );
++            
++    }
+ 	p->SetSource32( rSrc );
+ 	p->SetParent( this );
+ 	pModules->Insert( p, pModules->Count() );
+ 	SetModified( TRUE );
+-	return p;
++    return p;
+ }
+ 
+ void StarBASIC::Insert( SbxVariable* pVar )
+@@ -862,6 +896,12 @@ SbxVariable* StarBASIC::Find( const Stri
+ 				}
+ 				pNamed = p;
+ 			}
++			// Only variables qualified by the Module Name e.g. Sheet1.foo
++			// should work for Documant && Class type Modules
++			INT32 nType = p->GetModuleType();
++            //if ( nType == com::sun::star::script::ModuleType::Class || nType == com::sun::star::script::ModuleType::Document )
++            if ( nType == com::sun::star::script::ModuleType::Document )
++                continue;
+ 			// Sonst testen, ob das Element vorhanden ist
+ 			// GBLSEARCH-Flag rausnehmen (wg. Rekursion)
+ 			USHORT nGblFlag = p->GetFlags() & SBX_GBLSEARCH;
+diff --git basic/source/classes/sbxmod.cxx basic/source/classes/sbxmod.cxx
+index 42c4536..8ea4b64 100644
+--- basic/source/classes/sbxmod.cxx
++++ basic/source/classes/sbxmod.cxx
+@@ -51,6 +51,8 @@
+ #include <basic/hilight.hxx>
+ #include <basic/basrdll.hxx>
+ #include <vos/mutex.hxx>
++#include <basic/sbobjmod.hxx>
++#include <com/sun/star/lang/XServiceInfo.hpp>
+ 
+ // for the bsearch
+ #ifdef WNT
+@@ -65,6 +67,17 @@
+ 
+ #include <stdio.h>
+ 
++#include <comphelper/processfactory.hxx>
++#include <com/sun/star/script/XLibraryContainer.hpp>
++#include <com/sun/star/lang/XMultiServiceFactory.hpp>
++#include <com/sun/star/awt/XDialogProvider.hpp>
++#include <com/sun/star/awt/XTopWindow.hpp>
++#include <com/sun/star/awt/XControl.hpp>
++#include <com/sun/star/frame/XModel.hpp>
++#include <cppuhelper/implbase1.hxx>
++#include <comphelper/anytostring.hxx>
++
++using namespace ::com::sun::star; 
+ 
+ TYPEINIT1(SbModule,SbxObject)
+ TYPEINIT1(SbMethod,SbxMethod)
+@@ -72,6 +85,7 @@ TYPEINIT1(SbProperty,SbxProperty)
+ TYPEINIT1(SbProcedureProperty,SbxProperty)
+ TYPEINIT1(SbJScriptModule,SbModule)
+ TYPEINIT1(SbJScriptMethod,SbMethod)
++TYPEINIT1(SbObjModule,SbModule)
+ 
+ SV_DECL_VARARR(SbiBreakpoints,USHORT,4,4)
+ SV_IMPL_VARARR(SbiBreakpoints,USHORT)
+@@ -221,12 +235,13 @@ extern "C" int CDECL compare_strings( co
+ // Ein BASIC-Modul hat EXTSEARCH gesetzt, damit die im Modul enthaltenen
+ // Elemente von anderen Modulen aus gefunden werden koennen.
+ 
+-SbModule::SbModule( const String& rName )
++SbModule::SbModule( const String& rName, bool bVBACompat )
+ 		 : SbxObject( String( RTL_CONSTASCII_USTRINGPARAM("StarBASICModule") ) ),
+-		   pImage( NULL ), pBreaks( NULL ), pClassData( NULL ), mbVBACompat( false )
++		   pImage( NULL ), pBreaks( NULL ), pClassData( NULL ), mbVBACompat( bVBACompat ),  pDocObject( NULL ), bIsProxyModule( false )
+ {
+ 	SetName( rName );
+ 	SetFlag( SBX_EXTSEARCH | SBX_GBLSEARCH );
++	SetModuleType( com::sun::star::script::ModuleType::Normal );
+ }
+ 
+ SbModule::~SbModule()
+@@ -401,7 +416,10 @@ void SbModule::Clear()
+ 
+ SbxVariable* SbModule::Find( const XubString& rName, SbxClassType t )
+ {
++	// make sure a search in an uninstatiated class module will fail
+ 	SbxVariable* pRes = SbxObject::Find( rName, t );
++	if ( bIsProxyModule )
++		return NULL;
+ 	if( !pRes && pImage )
+ 	{
+ 		SbiInstance* pInst = pINST;
+@@ -561,6 +579,7 @@ void SbModule::SetSource32( const ::rtl:
+ 	aOUSource = r;
+ 	StartDefinitions();
+ 	SbiTokenizer aTok( r );
++        aTok.SetCompatible( IsVBACompat() );
+ 	while( !aTok.IsEof() )
+ 	{
+ 		SbiToken eEndTok = NIL;
+@@ -585,14 +604,6 @@ void SbModule::SetSource32( const ::rtl:
+ 				{
+ 					eEndTok = ENDPROPERTY; break;
+ 				}
+-				if( eCurTok == OPTION )
+-				{
+-					eCurTok = aTok.Next();
+-					mbVBACompat = ( eCurTok == VBASUPPORT ) && ( aTok.Next() == NUMBER ) && ( aTok.GetDbl()== 1 );
+-					if( eCurTok == COMPATIBLE 
+-					|| mbVBACompat )
+-						aTok.SetCompatible( true );
+-				}
+ 			}
+ 			eLastTok = eCurTok;
+ 		}
+@@ -731,10 +742,19 @@ void ClearUnoObjectsInRTL_Impl( StarBASI
+     if( ((StarBASIC*)p) != pBasic )
+ 	    ClearUnoObjectsInRTL_Impl_Rek( (StarBASIC*)p );
+ }
++bool SbModule::IsVBACompat()
++{
++	return mbVBACompat;
++}
+ 
++void SbModule::SetVBACompat( bool bCompat )
++{
++	mbVBACompat = bCompat;
++}
+ // Ausfuehren eines BASIC-Unterprogramms
+ USHORT SbModule::Run( SbMethod* pMeth )
+ {
++	OSL_TRACE("About to run %s, vba compatmode is %d", rtl::OUStringToOString( pMeth->GetName(), RTL_TEXTENCODING_UTF8 ).getStr(), mbVBACompat );
+ 	static USHORT nMaxCallLevel = 0;
+ 	static String aMSOMacroRuntimeLibName = String::CreateFromAscii( "Launcher" );
+ 	static String aMSOMacroRuntimeAppSymbol = String::CreateFromAscii( "Application" );
+@@ -826,10 +846,10 @@ USHORT SbModule::Run( SbMethod* pMeth )
+ 			if( pRt->pNext )
+ 				pRt->pNext->block();
+ 			pINST->pRun = pRt;
+-			if ( SbiRuntime ::isVBAEnabled() )
++			if ( mbVBACompat )
+                         {
+ 				pINST->EnableCompatibility( TRUE );
+-				pRt->SetVBAEnabled( true );
++				//pRt->SetVBAEnabled( true ); // can we get rid of this
+                         }
+ 			while( pRt->Step() ) {}
+ 			if( pRt->pNext )
+@@ -1404,7 +1424,6 @@ BOOL SbModule::LoadBinaryData( SvStream&
+     return bRet;
+ }
+ 
+-
+ BOOL SbModule::LoadCompleted()
+ {
+ 	SbxArray* p = GetMethods();
+@@ -2207,6 +2226,53 @@ SbJScriptMethod::~SbJScriptMethod()
+ 
+ 
+ /////////////////////////////////////////////////////////////////////////
++SbObjModule::SbObjModule( const com::sun::star::script::ModuleInfo& mInfo, bool bIsVbaCompatible )
++    : SbModule( mInfo.ModuleName, bIsVbaCompatible )
++{
++    SetModuleType( mInfo.ModuleType );
++    if ( mInfo.ModuleType == script::ModuleType::Form )
++    {
++        SetClassName( rtl::OUString::createFromAscii( "Form" ) );
++    }
++    else if ( mInfo.ModuleObject.is() )
++        SetUnoObject( uno::makeAny( mInfo.ModuleObject ) );
++}
++void
++SbObjModule::SetUnoObject( const uno::Any& aObj ) throw ( uno::RuntimeException )
++{
++    SbUnoObject* pUnoObj = PTR_CAST(SbUnoObject,(SbxVariable*)pDocObject);
++    if ( pUnoObj && pUnoObj->getUnoAny() == aObj ) // object is equal, nothing to do
++        return;
++    pDocObject = new SbUnoObject( GetName(), uno::makeAny( aObj ) );
++            
++    com::sun::star::uno::Reference< com::sun::star::lang::XServiceInfo > xServiceInfo( aObj, com::sun::star::uno::UNO_QUERY_THROW );
++    if( xServiceInfo->supportsService( rtl::OUString::createFromAscii( "org.openoffice.excel.Worksheet" ) ) )
++    {
++        SetClassName( rtl::OUString::createFromAscii( "Worksheet" ) );
++    }
++    else if( xServiceInfo->supportsService( rtl::OUString::createFromAscii( "org.openoffice.excel.Workbook" ) ) )
++    {
++        SetClassName( rtl::OUString::createFromAscii( "Workbook" ) );
++    }
++}
++
++SbxVariable*
++SbObjModule::GetObject() 
++{
++    return pDocObject;
++}
++SbxVariable*
++SbObjModule::Find( const XubString& rName, SbxClassType t )
++{
++    //OSL_TRACE("SbObjectModule find for %s", rtl::OUStringToOString(  rName, RTL_TEXTENCODING_UTF8 ).getStr() );
++    SbxVariable* pVar = NULL;
++    if ( !pVar && pDocObject)
++        pVar = pDocObject->Find( rName, t );
++    if ( !pVar )
++        pVar = SbModule::Find( rName, t );
++    return pVar;
++}
++/////////////////////////////////////////////////////////////////////////
+ 
+ SbProperty::SbProperty( const String& r, SbxDataType t, SbModule* p )
+ 		: SbxProperty( r, t ), pMod( p )
+diff --git basic/source/comp/codegen.cxx basic/source/comp/codegen.cxx
+index 9f88fb6..4674134 100644
+--- basic/source/comp/codegen.cxx
++++ basic/source/comp/codegen.cxx
+@@ -130,12 +130,12 @@ void SbiCodeGen::Save()
+ 	// OPTION EXPLICIT-Flag uebernehmen
+ 	if( pParser->bExplicit )
+ 		p->SetFlag( SBIMG_EXPLICIT );
+-	if( pParser->IsVBASupportOn() )
+-		p->SetFlag( SBIMG_VBASUPPORT );
+ 	
+ 	int nIfaceCount = 0;
+-	if( pParser->bClassModule )
++	if( rMod.mnType == com::sun::star::script::ModuleType::Class )
+ 	{
++                OSL_TRACE("COdeGen::save() classmodule processing");
++		rMod.bIsProxyModule = true;
+ 		p->SetFlag( SBIMG_CLASSMODULE );
+ 		pCLASSFAC->AddClassModule( &rMod );
+ 
+@@ -158,6 +158,10 @@ void SbiCodeGen::Save()
+ 	else
+ 	{
+ 		pCLASSFAC->RemoveClassModule( &rMod );
++		// Only a ClassModule can revert to Normal
++                if ( rMod.mnType == com::sun::star::script::ModuleType::Class )
++			rMod.mnType = com::sun::star::script::ModuleType::Normal;
++		rMod.bIsProxyModule = false;
+ 	}
+ 	if( pParser->bText )
+ 		p->SetFlag( SBIMG_COMPARETEXT );
+@@ -240,6 +244,8 @@ void SbiCodeGen::Save()
+ 					if( nPass == 1 )
+ 						aPropName = aPropName.Copy( aIfaceName.Len() + 1 );
+ 					SbProcedureProperty* pProcedureProperty = NULL;
++                                        OSL_TRACE("*** getProcedureProperty for thing %s",
++						rtl::OUStringToOString( aPropName,RTL_TEXTENCODING_UTF8 ).getStr() );
+ 					pProcedureProperty = rMod.GetProcedureProperty( aPropName, ePropType );
+ 				}
+ 				if( nPass == 1 )
+diff --git basic/source/comp/parser.cxx basic/source/comp/parser.cxx
+index 3259f77..1a4dc06 100644
+--- basic/source/comp/parser.cxx
++++ basic/source/comp/parser.cxx
+@@ -145,7 +145,8 @@ SbiParser::SbiParser( StarBASIC* pb, SbM
+ 	bNewGblDefs =
+ 	bSingleLineIf =
+ 	bExplicit = FALSE;
+-	bClassModule = FALSE;
++	bClassModule = ( pm->GetModuleType() == com::sun::star::script::ModuleType::Class );
++	OSL_TRACE("Parser - %s, bClassModule %d", rtl::OUStringToOString( pm->GetName(), RTL_TEXTENCODING_UTF8 ).getStr(), bClassModule );
+ 	pPool	 = &aPublics;
+ 	for( short i = 0; i < 26; i++ )
+ 		eDefTypes[ i ] = SbxVARIANT;    // Kein expliziter Defaulttyp
+@@ -158,6 +159,10 @@ SbiParser::SbiParser( StarBASIC* pb, SbM
+ 
+ 	rTypeArray = new SbxArray; // Array fuer Benutzerdefinierte Typen
+ 	rEnumArray = new SbxArray; // Array for Enum types
++	bVBASupportOn = pm->IsVBACompat();
++	if ( bVBASupportOn )
++		EnableCompatibility();
++
+ }
+ 
+ 
+@@ -778,8 +783,9 @@ void SbiParser::Option()
+ 
+ 		case CLASSMODULE:
+ 			bClassModule = TRUE; 
++			aGen.GetModule().SetModuleType( com::sun::star::script::ModuleType::Class );
+ 			break;
+-		case VBASUPPORT:
++		case VBASUPPORT: // Option VBASupport used to override the module mode ( in fact this must reset the mode
+ 			if( Next() == NUMBER )
+ 			{
+ 				if ( nVal == 1 || nVal == 0 )
+@@ -787,6 +793,10 @@ void SbiParser::Option()
+ 					bVBASupportOn = ( nVal == 1 );
+ 					if ( bVBASupportOn )
+ 						EnableCompatibility();
++					// if the module setting is different
++					// reset it to what the Option tells us
++					if ( bVBASupportOn != aGen.GetModule().IsVBACompat() )
++						aGen.GetModule().SetVBACompat( bVBASupportOn );
+ 					break;
+ 				}
+ 			}
+diff --git basic/source/inc/codegen.hxx basic/source/inc/codegen.hxx
+index ad11d02..a054af7 100644
+--- basic/source/inc/codegen.hxx
++++ basic/source/inc/codegen.hxx
+@@ -56,6 +56,7 @@ public:
+ 	void GenStmnt();			// evtl. Statement-Opcode erzeugen
+ 	UINT32 GetPC();
+ 	UINT32 GetOffset()				{ return GetPC() + 1; }
++    SbModule& GetModule() { return rMod; } 
+ 	void Save();
+ 
+ 	// #29955 for-Schleifen-Ebene pflegen
+diff --git basic/source/inc/image.hxx basic/source/inc/image.hxx
+index 8a454cf..c371a85 100644
+--- basic/source/inc/image.hxx
++++ basic/source/inc/image.hxx
+@@ -109,6 +109,5 @@ public:
+ #define	SBIMG_COMPARETEXT	0x0002	// OPTION COMPARE TEXT ist aktiv
+ #define	SBIMG_INITCODE		0x0004	// Init-Code vorhanden
+ #define	SBIMG_CLASSMODULE	0x0008	// OPTION ClassModule is active
+-#define	SBIMG_VBASUPPORT	0x0020	// OPTION VBASupport is 1
+ 
+ #endif
+diff --git basic/source/inc/namecont.hxx basic/source/inc/namecont.hxx
+index 24778f7..f2760b8 100644
+--- basic/source/inc/namecont.hxx
++++ basic/source/inc/namecont.hxx
+@@ -39,6 +39,7 @@
+ #include <com/sun/star/script/XLibraryContainerPassword.hpp>
+ #include <com/sun/star/script/XLibraryContainerExport.hpp>
+ #include <com/sun/star/script/XLibraryQueryExecutable.hpp>
++#include <com/sun/star/script/ModuleInfo.hpp>
+ #include <com/sun/star/container/XNameContainer.hpp>
+ #include <com/sun/star/container/XContainer.hpp>
+ #include <com/sun/star/ucb/XSimpleFileAccess.hpp>
+@@ -573,6 +574,8 @@ private:
+ protected:
+     inline  sal_Bool    implIsModified() const  { return mbIsModified; }
+             void        implSetModified( sal_Bool _bIsModified );
++typedef std::hash_map< rtl::OUString, com::sun::star::script::ModuleInfo, ::rtl::OUStringHash, ::std::equal_to< ::rtl::OUString > > NameToInfoHash;
++    NameToInfoHash hBasicInfo;
+ 
+ private:
+     /** checks whether the lib is readonly, or a readonly link, throws an IllegalArgumentException if so
+diff --git basic/source/inc/scriptcont.hxx basic/source/inc/scriptcont.hxx
+index 1679b30..9a7bb87 100644
+--- basic/source/inc/scriptcont.hxx
++++ basic/source/inc/scriptcont.hxx
+@@ -33,6 +33,9 @@
+ 
+ #include "namecont.hxx"
+ #include <basic/basmgr.hxx>
++#include <com/sun/star/script/XBasicLibraryInfo.hpp>
++#include <cppuhelper/implbase1.hxx>
++#include <comphelper/uno3.hxx>
+ 
+ class BasicManager;
+ 
+@@ -139,13 +142,17 @@ public:
+ };
+ 
+ //============================================================================
++typedef std::hash_map< rtl::OUString, com::sun::star::script::ModuleInfo, ::rtl::OUStringHash, ::std::equal_to< ::rtl::OUString > > NameToInfoHash;
+ 
++typedef ::cppu::ImplHelper1 <  ::com::sun::star::script::XBasicLibraryInfo >  SfxScriptLibrary_BASE;
+ class SfxScriptLibrary : public SfxLibrary
++			, public SfxScriptLibrary_BASE
+ {
+     friend class SfxScriptLibraryContainer;
+ 
+ 	sal_Bool mbLoadedSource;
+ 	sal_Bool mbLoadedBinary;
++	sal_Bool mbVBA;
+ 
+ 	// Provide modify state including resources
+ 	virtual sal_Bool isModified( void );
+@@ -171,9 +178,36 @@ public:
+ 	    const ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XSimpleFileAccess >& xSFI,
+         const ::rtl::OUString& aLibInfoFileURL, const ::rtl::OUString& aStorageURL, sal_Bool ReadOnly
+     );
+-
++    // XNameReplace
++    virtual void SAL_CALL replaceByName( const ::rtl::OUString& aName, const ::com::sun::star::uno::Any& aElement ) 
++		throw(::com::sun::star::lang::IllegalArgumentException, 
++			  ::com::sun::star::container::NoSuchElementException, 
++			  ::com::sun::star::lang::WrappedTargetException, 
++			  ::com::sun::star::uno::RuntimeException);
++
++    // Methods XNameContainer
++    virtual void SAL_CALL insertByName( const ::rtl::OUString& aName, const ::com::sun::star::uno::Any& aElement )
++		throw(::com::sun::star::lang::IllegalArgumentException, 
++			  ::com::sun::star::container::ElementExistException, 
++			  ::com::sun::star::lang::WrappedTargetException, 
++			  ::com::sun::star::uno::RuntimeException);
++    virtual void SAL_CALL removeByName( const ::rtl::OUString& Name ) 
++		throw(::com::sun::star::container::NoSuchElementException, 
++			  ::com::sun::star::lang::WrappedTargetException, 
++			  ::com::sun::star::uno::RuntimeException);
+     static bool containsValidModule( const ::com::sun::star::uno::Any& _rElement );
++    DECLARE_XINTERFACE()
++    DECLARE_XTYPEPROVIDER()
++
++    // XBasicLibraryInfo
++ 
++    // Attributes
++    virtual ::sal_Bool SAL_CALL getVBACompatMode() throw (::com::sun::star::uno::RuntimeException);
++    virtual void SAL_CALL setVBACompatMode( ::sal_Bool _vbacompatmodeon ) throw (::com::sun::star::uno::RuntimeException);
+ 
++    // Methods
++    virtual ::com::sun::star::script::ModuleInfo SAL_CALL getModuleInfo( const ::rtl::OUString& ModuleName ) throw (::com::sun::star::uno::RuntimeException);
++    
+ protected:
+ 	virtual bool SAL_CALL isLibraryElementValid( ::com::sun::star::uno::Any aElement ) const;
+ };
+diff --git basic/source/runtime/methods1.cxx basic/source/runtime/methods1.cxx
+index e72f78b..bb24705 100644
+--- basic/source/runtime/methods1.cxx
++++ basic/source/runtime/methods1.cxx
+@@ -44,6 +44,7 @@
+ #ifndef _SBX_HXX
+ #include <basic/sbx.hxx>
+ #endif
++#include <basic/sbstar.hxx>
+ #include <svtools/zforlist.hxx>
+ #include <tools/fsys.hxx>
+ #include <tools/urlobj.hxx>
+@@ -64,6 +65,7 @@
+ #endif
+ 
+ #include <vcl/jobset.hxx>
++#include <basic/sbobjmod.hxx>
+ 
+ #include "sbintern.hxx"
+ #include "runtime.hxx"
+@@ -2594,14 +2596,14 @@ RTLFUNC(Me)
+ 
+ 	SbModule* pActiveModule = pINST->GetActiveModule();
+ 	SbClassModuleObject* pClassModuleObject = PTR_CAST(SbClassModuleObject,pActiveModule);
++    SbxVariableRef refVar = rPar.Get(0);
+ 	if( pClassModuleObject == NULL )
+ 	{
+-		StarBASIC::Error( SbERR_INVALID_USAGE_OBJECT );
++        SbObjModule* pMod = PTR_CAST(SbObjModule,pActiveModule);
++        if ( pMod )
++            refVar->PutObject( pMod );
+ 	}
+ 	else
+-	{
+-		SbxVariableRef refVar = rPar.Get(0);
+ 		refVar->PutObject( pClassModuleObject );
+-	}
+ }
+ 
+diff --git basic/source/runtime/runtime.cxx basic/source/runtime/runtime.cxx
+index 07f70a6..69c75b3 100644
+--- basic/source/runtime/runtime.cxx
++++ basic/source/runtime/runtime.cxx
+@@ -55,7 +55,8 @@ bool SbiRuntime::isVBAEnabled()
+ 	bool result = false;
+ 	SbiInstance* pInst = pINST;
+ 	if ( pInst && pINST->pRun )
+-		result = pInst->pRun->GetImageFlag( SBIMG_VBASUPPORT );
++		//result = pInst->pRun->GetImageFlag( SBIMG_VBASUPPORT );
++		result = pInst->pRun->bVBAEnabled;
+ 	return result; 
+ }
+ 
+@@ -66,6 +67,24 @@ void StarBASIC::StaticEnableReschedule( 
+ {
+     bStaticGlobalEnableReschedule = bReschedule;
+ }
++void StarBASIC::SetVBAEnabled( BOOL bEnabled )
++{
++    if ( bDocBasic )
++    {
++        bVBAEnabled = bEnabled;
++    }
++}
++
++BOOL StarBASIC::isVBAEnabled()
++{
++    if ( bDocBasic )
++    { 
++        if( SbiRuntime::isVBAEnabled() )
++            return TRUE;
++        return bVBAEnabled;
++    }
++    return FALSE;
++}
+ 
+ 
+ struct SbiArgvStack {					// Argv stack:
+@@ -522,6 +541,7 @@ SbiRuntime::SbiRuntime( SbModule* pm, Sb
+ 	nForLvl   = 0;
+ 	nOps	  = 0;
+ 	refExprStk = new SbxArray;
++	SetVBAEnabled( pMod->IsVBACompat() );
+ #if defined GCC
+ 	SetParameters( pe ? pe->GetParameters() : (class SbxArray *)NULL );
+ #else
+@@ -529,7 +549,6 @@ SbiRuntime::SbiRuntime( SbModule* pm, Sb
+ #endif
+ 	pRefSaveList = NULL;
+ 	pItemStoreList = NULL;
+-	bVBAEnabled = isVBAEnabled();
+ }
+ 
+ SbiRuntime::~SbiRuntime()
+diff --git basic/source/uno/namecont.cxx basic/source/uno/namecont.cxx
+index 7af486f..a777d23 100644
+--- basic/source/uno/namecont.cxx
++++ basic/source/uno/namecont.cxx
+@@ -75,7 +75,8 @@
+ #endif
+ #include <cppuhelper/exc_hlp.hxx>
+ #include <basic/sbmod.hxx>
+-
++#include "sbunoobj.hxx"
++#include <com/sun/star/script/XBasicLibraryInfo.hpp>
+ 
+ namespace basic
+ {
+@@ -1721,10 +1722,17 @@ void SfxLibraryContainer::implImportLibD
+     {
+ 	    sal_Int32 nElementCount = rLib.aElementNames.getLength();
+ 	    const OUString* pElementNames = rLib.aElementNames.getConstArray();
++            Reference< XNameContainer > xLib( pLib );
++            Reference< XBasicLibraryInfo > xLibInfo( xLib, UNO_QUERY );
+ 	    Any aDummyElement = createEmptyLibraryElement();
+ 	    for( sal_Int32 i = 0 ; i < nElementCount ; i++ )
+ 	    {
++                    // default the module type
++                    com::sun::star::script::ModuleInfo mInfo;
++                    mInfo.ModuleType = ModuleType::Normal;         
++
+ 		    pLib->maNameContainer.insertByName( pElementNames[i], aDummyElement );
++                    pLib->hBasicInfo[  pElementNames[i] ] = mInfo;
+ 	    }
+         pLib->mbPasswordProtected = rLib.bPasswordProtected;
+         pLib->mbReadOnly = rLib.bReadOnly;
+@@ -2069,11 +2077,11 @@ Reference< XNameContainer > SAL_CALL Sfx
+ {
+     LibraryContainerMethodGuard aGuard( *this );
+ 	SfxLibrary* pNewLib = implCreateLibrary( Name );
++	Reference< XNameAccess > xNameAccess = static_cast< XNameAccess* >( pNewLib );
+     pNewLib->maLibElementFileExtension = maLibElementFileExtension;
+ 
+ 	createVariableURL( pNewLib->maUnexpandedStorageURL, Name, maInfoFileName, true );
+ 
+-	Reference< XNameAccess > xNameAccess = static_cast< XNameAccess* >( pNewLib );
+ 	Any aElement;
+ 	aElement <<= xNameAccess;
+ 	maNameContainer.insertByName( Name, aElement );
+@@ -2099,6 +2107,7 @@ Reference< XNameAccess > SAL_CALL SfxLib
+ 
+ 
+ 	SfxLibrary* pNewLib = implCreateLibraryLink( Name, aLibInfoFileURL, aLibDirURL, ReadOnly );
++    Reference< XNameAccess > xRet = static_cast< XNameAccess* >( pNewLib );
+     pNewLib->maLibElementFileExtension = maLibElementFileExtension;
+     pNewLib->maUnexpandedStorageURL = aUnexpandedStorageURL;
+ 
+@@ -2108,7 +2117,6 @@ Reference< XNameAccess > SAL_CALL SfxLib
+     /*sal_Bool bReadIndexFile = */implLoadLibraryIndexFile( pNewLib, aLibDesc, xDummyStor, aInitFileName );
+     implImportLibDescriptor( pNewLib, aLibDesc );
+ 
+-	Reference< XNameAccess > xRet = static_cast< XNameAccess* >( pNewLib );
+ 	Any aElement;
+ 	aElement <<= xRet;
+ 	maNameContainer.insertByName( Name, aElement );
+diff --git basic/source/uno/scriptcont.cxx basic/source/uno/scriptcont.cxx
+index f47dc64..e64041a 100644
+--- basic/source/uno/scriptcont.cxx
++++ basic/source/uno/scriptcont.cxx
+@@ -57,7 +57,7 @@
+ // For password functionality
+ #include <tools/urlobj.hxx>
+ 
+-
++#include <com/sun/star/script/ModuleSourceInfo.hpp>
+ #include <svtools/pathoptions.hxx>
+ #include <svtools/sfxecode.hxx>
+ #include <svtools/ehdl.hxx>
+@@ -214,6 +214,7 @@ void SAL_CALL SfxScriptLibraryContainer:
+ 	xmlscript::ModuleDescriptor aMod;
+ 	aMod.aName = aElementName;
+ 	aMod.aLanguage = maScriptLanguage;
++	// make sure we export source
+ 	aElement >>= aMod.aCode;
+ 	xmlscript::exportScriptModule( xHandler, aMod );
+ }
+@@ -1120,6 +1121,7 @@ SfxScriptLibrary::SfxScriptLibrary( Modi
+ 	: SfxLibrary( _rModifiable, getCppuType( (const OUString *)0 ), xMSF, xSFI )
+     , mbLoadedSource( sal_False )
+     , mbLoadedBinary( sal_False )
++    , mbVBA( sal_False )
+ {
+ }
+ 
+@@ -1133,9 +1135,86 @@ SfxScriptLibrary::SfxScriptLibrary( Modi
+ 						aLibInfoFileURL, aStorageURL, ReadOnly)
+     , mbLoadedSource( sal_False )
+     , mbLoadedBinary( sal_False )
++    , mbVBA( sal_False )
++{
++}
++
++IMPLEMENT_FORWARD_XINTERFACE2( SfxScriptLibrary, SfxLibrary, SfxScriptLibrary_BASE );
++IMPLEMENT_FORWARD_XTYPEPROVIDER2( SfxScriptLibrary, SfxLibrary, SfxScriptLibrary_BASE );
++
++::sal_Bool SAL_CALL 
++SfxScriptLibrary::getVBACompatMode() throw (RuntimeException)
++{
++    return mbVBA;
++}
++
++void SAL_CALL 
++SfxScriptLibrary::setVBACompatMode( ::sal_Bool _vbacompatmodeon ) throw (RuntimeException)
++{
++    mbVBA = _vbacompatmodeon;
++}
++
++// Methods
++::com::sun::star::script::ModuleInfo SAL_CALL 
++SfxScriptLibrary::getModuleInfo( const ::rtl::OUString& ModuleName ) throw (RuntimeException)
++{
++	::com::sun::star::script::ModuleInfo mInfo;
++	NameToInfoHash::iterator it_end = hBasicInfo.end();
++	NameToInfoHash::iterator it = hBasicInfo.find( ModuleName );
++	if ( it != it_end )
++		mInfo = it->second;
++
++	return mInfo;
++}
++
++void SAL_CALL 
++SfxScriptLibrary::replaceByName( const ::rtl::OUString& aName, const ::com::sun::star::uno::Any& aElement ) 
++		throw(::com::sun::star::lang::IllegalArgumentException, 
++			  ::com::sun::star::container::NoSuchElementException, 
++			  ::com::sun::star::lang::WrappedTargetException, 
++			  ::com::sun::star::uno::RuntimeException)
+ {
++	SfxLibrary::replaceByName( aName, aElement );
+ }
+ 
++// Methods XNameContainer
++void SAL_CALL 
++SfxScriptLibrary::insertByName( const ::rtl::OUString& aName, const ::com::sun::star::uno::Any& aElement )
++		throw(::com::sun::star::lang::IllegalArgumentException, 
++			  ::com::sun::star::container::ElementExistException, 
++			  ::com::sun::star::lang::WrappedTargetException, 
++			  ::com::sun::star::uno::RuntimeException)
++{
++    OSL_TRACE("***** insertByName module %s", rtl::OUStringToOString( aName, RTL_TEXTENCODING_UTF8 ).getStr() );
++
++	NameToInfoHash::iterator it_end = hBasicInfo.end();
++	NameToInfoHash::iterator it = hBasicInfo.find( aName );
++
++	if ( it != it_end )
++		throw ElementExistException(); // more detail please
++
++	ModuleSourceInfo mInfo;
++	if ( aElement >>= mInfo )
++	{
++		hBasicInfo[ aName ] = mInfo;
++		uno::Any aTmpElement( mInfo.ModuleSource );
++		SfxLibrary::insertByName( aName, aTmpElement );
++	}
++	else
++		SfxLibrary::insertByName( aName, aElement );
++}
++
++void SAL_CALL 
++SfxScriptLibrary::removeByName( const ::rtl::OUString& Name ) 
++		throw(::com::sun::star::container::NoSuchElementException, 
++			  ::com::sun::star::lang::WrappedTargetException, 
++			  ::com::sun::star::uno::RuntimeException)
++{
++	SfxLibrary::removeByName( Name );
++}
++
++
++
+ // Provide modify state including resources
+ sal_Bool SfxScriptLibrary::isModified( void )
+ {
+diff --git offapi/com/sun/star/script/XBasicLibraryInfo.idl offapi/com/sun/star/script/XBasicLibraryInfo.idl
+new file mode 100644
+index 0000000..0086a1b
+--- /dev/null
++++ offapi/com/sun/star/script/XBasicLibraryInfo.idl
+@@ -0,0 +1,19 @@
++#ifndef __com_sun_star_script_XBasicLibraryInfo_idl__ 
++#define __com_sun_star_script_XBasicLibraryInfo_idl__ 
++  
++#ifndef __com_sun_star_uno_XInterface_idl__ 
++#include <com/sun/star/uno/XInterface.idl> 
++#endif 
++#include <com/sun/star/script/ModuleInfo.idl> 
++#endif 
++module com {  module sun {  module star {  module script {  
++  
++interface XBasicLibraryInfo: com::sun::star::uno::XInterface
++{ 
++ 
++//============================================================================= 
++    [attribute ] boolean VBACompatMode;
++    ModuleInfo getModuleInfo( [in] string ModuleName );
++  
++}; }; }; };  
++}; 
+diff --git sc/inc/servuno.hxx sc/inc/servuno.hxx
+index a0e7f94..11bbabc 100644
+--- sc/inc/servuno.hxx
++++ sc/inc/servuno.hxx
+@@ -93,8 +93,8 @@ class ScDocShell;
+ 
+ #define SC_SERVICE_FORMULAPARS  38
+ #define SC_SERVICE_OPCODEMAPPER 39
+-
+-#define SC_SERVICE_COUNT        40
++#define SC_SERVICE_VBAOBJECTPROVIDER   40
++#define SC_SERVICE_COUNT        41
+ #define SC_SERVICE_INVALID		USHRT_MAX
+ 
+ 
+diff --git sc/source/filter/excel/excimp8.cxx sc/source/filter/excel/excimp8.cxx
+index 0df678a..aff8877 100644
+--- sc/source/filter/excel/excimp8.cxx
++++ sc/source/filter/excel/excimp8.cxx
+@@ -103,6 +103,7 @@
+ 
+ #include <com/sun/star/document/XDocumentProperties.hpp>
+ #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
++#include <com/sun/star/script/ModuleInfo.hpp>
+ 
+ 
+ using namespace com::sun::star;
+@@ -110,8 +111,8 @@ using namespace com::sun::star;
+ 
+ #define	INVALID_POS		0xFFFFFFFF
+ 
+-
+-
++// defined in docfunc.cxx ( really this needs a new name )
++script::ModuleInfo lcl_InitModuleInfo( SfxObjectShell& rDocSh, String& sModule );
+ 
+ ImportExcel8::ImportExcel8( XclImpRootData& rImpData, SvStream& rStrm ) :
+     ImportExcel( rImpData, rStrm ), mnTab(0)
+@@ -273,6 +274,7 @@ bool lcl_hasVBAEnabled()
+ 
+ void ImportExcel8::ReadBasic( void )
+ {
++    //bHasBasic = TRUE;
+     bHasBasic = TRUE;
+ 
+     SfxObjectShell* pShell = GetDocShell();
+@@ -302,6 +304,10 @@ void ImportExcel8::EndSheet( void )
+ 
+ void ImportExcel8::PostDocLoad( void )
+ {
++    // delay reading basic until sheet object ( codenames etc. ) are read
++
++    if ( bHasBasic ) 
++        ReadBasic();
+     // #i11776# filtered ranges before outlines and hidden rows
+     if( pExcRoot->pAutoFilterBuffer )
+         pExcRoot->pAutoFilterBuffer->Apply();
+diff --git sc/source/filter/excel/read.cxx sc/source/filter/excel/read.cxx
+index 0fef232..a868e17 100644
+--- sc/source/filter/excel/read.cxx
++++ sc/source/filter/excel/read.cxx
+@@ -947,7 +947,8 @@ FltError ImportExcel8::Read( void )
+ 					case 0x22:	Rec1904(); break;		// 1904			[ 2345   ]
+ 					case 0x56:	Builtinfmtcnt(); break;	// BUILTINFMTCNT[  34    ]
+ 					case 0x8D:	Hideobj(); break;		// HIDEOBJ		[  345   ]
+-					case 0xD3:	ReadBasic(); break;
++					case 0xD3:	/*ReadBasic()*/bHasBasic = true; break;
++//					case 0xD3:	ReadBasic(); break;
+                     case 0xDE:  Olesize(); break;
+ 					case 0x01BA: Codename( TRUE ); break;
+ 
+diff --git sc/source/filter/excel/xiescher.cxx sc/source/filter/excel/xiescher.cxx
+index 9c687ed..c8339df 100644
+--- sc/source/filter/excel/xiescher.cxx
++++ sc/source/filter/excel/xiescher.cxx
+@@ -834,7 +834,7 @@ bool XclImpTbxControlObj::FillMacroDescr
+         {
+             // set the macro name
+             rEvent.ScriptType = XclControlObjHelper::GetTbxScriptType();
+-            rEvent.ScriptCode = XclControlObjHelper::GetScMacroName( GetMacroName() );
++            rEvent.ScriptCode = XclControlObjHelper::GetScMacroName( GetMacroName(), GetDocShell() );
+             return true;
+         }
+     }
+@@ -1728,7 +1728,7 @@ SdrObject* XclImpDffManager::ProcessObj(
+             if( ScMacroInfo* pInfo = ScDrawLayer::GetMacroInfo( xSdrObj.get(), TRUE ) )
+             {
+                 if ( rMacro.Len() > 0 )
+-                pInfo->SetMacro( XclControlObjHelper::GetScMacroName( rMacro ) );
++                pInfo->SetMacro( XclControlObjHelper::GetScMacroName( rMacro, GetDocShell() ) );
+                 if ( aHlink.getLength() > 0 )
+                 pInfo->SetHlink( aHlink );
+             }
+diff --git sc/source/filter/excel/xlescher.cxx sc/source/filter/excel/xlescher.cxx
+index 8e8e694..693a323 100644
+--- sc/source/filter/excel/xlescher.cxx
++++ sc/source/filter/excel/xlescher.cxx
+@@ -37,7 +37,10 @@
+ #include "xistream.hxx"
+ #include "xestream.hxx"
+ #include "globstr.hrc"
+-
++#include <sfx2/objsh.hxx>
++#include <basic/sbstar.hxx>
++#include <basic/sbmod.hxx>
++#include <basic/sbmeth.hxx>
+ using ::rtl::OUString;
+ using ::com::sun::star::uno::Reference;
+ using ::com::sun::star::uno::UNO_QUERY;
+@@ -405,9 +408,16 @@ OUString XclControlObjHelper::GetTbxScri
+ #define EXC_TBX_MACRONAME_PRE "vnd.sun.star.script:Standard."
+ #define EXC_TBX_MACRONAME_SUF "?language=Basic&location=document"
+ 
+-OUString XclControlObjHelper::GetScMacroName( const String& rXclMacroName )
++OUString XclControlObjHelper::GetScMacroName( const String& rXclMacroName, SfxObjectShell* pDocShell )
+ {
+-    return CREATE_OUSTRING( EXC_TBX_MACRONAME_PRE ) + rXclMacroName + CREATE_OUSTRING( EXC_TBX_MACRONAME_SUF );
++    String sTmp( rXclMacroName );
++    if (  ( sTmp.Search( '.' ) == STRING_NOTFOUND) && pDocShell )
++                    if( StarBASIC* pBasic = pDocShell->GetBasic() )
++                        if( SbMethod* pMethod = dynamic_cast< SbMethod* >( pBasic->Find( sTmp, SbxCLASS_METHOD ) ) )
++                            if( SbModule* pModule = pMethod->GetModule() )
++                                sTmp.Insert( '.', 0 ).Insert( pModule->GetName(), 0 );
++    
++    return CREATE_OUSTRING( EXC_TBX_MACRONAME_PRE ) + sTmp + CREATE_OUSTRING( EXC_TBX_MACRONAME_SUF );
+ }
+ 
+ String XclControlObjHelper::GetXclMacroName( const OUString& rScMacroName )
+diff --git sc/source/filter/inc/xlescher.hxx sc/source/filter/inc/xlescher.hxx
+index e28b1c4..9263024 100644
+--- sc/source/filter/inc/xlescher.hxx
++++ sc/source/filter/inc/xlescher.hxx
+@@ -278,7 +278,7 @@ public:
+     static ::rtl::OUString GetTbxScriptType();
+ 
+     /** Returns the Calc macro name from an Excel macro name. */
+-    static ::rtl::OUString GetScMacroName( const String& rXclMacroName );
++    static ::rtl::OUString GetScMacroName( const String& rXclMacroName, SfxObjectShell* pShell = NULL );
+     /** Returns the Excel macro name from a Calc macro name. */
+     static String       GetXclMacroName( const ::rtl::OUString& rScMacroName );
+ };
+diff --git sc/source/ui/docshell/docfunc.cxx sc/source/ui/docshell/docfunc.cxx
+index d178786..dcedaf3 100644
+--- sc/source/ui/docshell/docfunc.cxx
++++ sc/source/ui/docshell/docfunc.cxx
+@@ -51,6 +51,12 @@
+ #include <svtools/zforlist.hxx>
+ #include <svtools/PasswordHelper.hxx>
+ 
++#include <basic/sbstar.hxx>
++#include <com/sun/star/container/XNameContainer.hpp>
++#include <com/sun/star/script/XLibraryContainer.hpp>
++#include <com/sun/star/script/ModuleSourceInfo.hpp>
++#include <com/sun/star/script/ModuleType.hpp>
++
+ #include <list>
+ 
+ #include "docfunc.hxx"
+@@ -99,6 +105,7 @@
+ using namespace com::sun::star;
+ using ::com::sun::star::uno::Sequence;
+ 
++
+ // STATIC DATA -----------------------------------------------------------
+ 
+ //========================================================================
+@@ -2021,6 +2028,92 @@ BOOL ScDocFunc::MoveBlock( const ScRange
+ }
+ 
+ //------------------------------------------------------------------------
++uno::Reference< uno::XInterface > GetDocModuleObject( SfxObjectShell& rDocSh, String& sCodeName )
++{
++    uno::Reference< lang::XMultiServiceFactory> xSF(rDocSh.GetModel(), uno::UNO_QUERY);
++    uno::Reference< container::XNameAccess > xVBACodeNamedObjectAccess;
++    uno::Reference< uno::XInterface > xDocModuleApiObject;
++    if ( xSF.is() )
++    {
++        xVBACodeNamedObjectAccess.set( xSF->createInstance( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "org.openoffice.vba.VBAObjectModuleObjectProvider"))), uno::UNO_QUERY );    
++        xDocModuleApiObject.set( xVBACodeNamedObjectAccess->getByName( sCodeName ), uno::UNO_QUERY );    
++    }
++    return xDocModuleApiObject;
++
++}
++
++script::ModuleSourceInfo lcl_InitModuleInfo( SfxObjectShell& rDocSh, String& sModule, String& sSource )
++{
++    ::rtl::OUString aModName( sModule );
++    ::rtl::OUString sVbaOption( RTL_CONSTASCII_USTRINGPARAM( "Rem Attribute VBA_ModuleType=VBADocumentModule\nOption VBASupport 1\n" ));
++    script::ModuleSourceInfo sModuleInfo;
++    sModuleInfo.ModuleName = aModName;
++    if ( sSource.Len() > 0 )
++        sModuleInfo.ModuleSource = sSource;
++    else
++        sModuleInfo.ModuleSource = sVbaOption;
++    sModuleInfo.ModuleType = script::ModuleType::Document;
++    sModuleInfo.ModuleObject = GetDocModuleObject( rDocSh, sModule );
++    return sModuleInfo;
++}
++
++void lcl_InsertModule( ScDocShell& rDocSh, SCTAB nTab, String& sModuleName, String& sSource )
++{
++    SFX_APP()->EnterBasicCall();
++    script::ModuleSourceInfo sModuleInfo = lcl_InitModuleInfo(  rDocSh, sModuleName, sSource );
++    uno::Reference< script::XLibraryContainer > xLibContainer = rDocSh.GetBasicContainer();
++    DBG_ASSERT( xLibContainer.is(), "No BasicContainer!" );
++
++    uno::Reference< container::XNameContainer > xLib;
++    if( xLibContainer.is() )
++    {
++        String aLibName( RTL_CONSTASCII_USTRINGPARAM( "Standard" ) );
++        uno::Any aLibAny = xLibContainer->getByName( aLibName );
++        aLibAny >>= xLib;
++    }
++    if( xLib.is() )
++    {
++        // if the Module with codename exists then find a new name
++        sal_Int32 nNum = 1;
++        sModuleInfo.ModuleName = sModuleName;
++        while( xLib->hasByName( sModuleInfo.ModuleName  ) )
++        {
++            sModuleInfo.ModuleName = rtl::OUString::createFromAscii( "Sheet" ) + rtl::OUString::valueOf( nNum );
++            nNum += 1;
++        }
++        uno::Any aSourceAny;
++        aSourceAny <<= sModuleInfo;
++        xLib->insertByName( sModuleInfo.ModuleName, aSourceAny );
++        ScDocument* pDoc = rDocSh.GetDocument();
++        String sCodeName( sModuleInfo.ModuleName );
++        pDoc->SetCodeName( nTab, sCodeName );
++    }
++    SFX_APP()->LeaveBasicCall();
++}
++
++void lcl_DeleteModule( ScDocShell& rDocSh, String& sModuleName )
++{
++    SFX_APP()->EnterBasicCall();
++    uno::Reference< script::XLibraryContainer > xLibContainer = rDocSh.GetBasicContainer();
++    DBG_ASSERT( xLibContainer.is(), "No BasicContainer!" );
++
++    uno::Reference< container::XNameContainer > xLib;
++    if( xLibContainer.is() )
++    {
++        String aLibName( RTL_CONSTASCII_USTRINGPARAM( "Standard" ) );
++        uno::Any aLibAny = xLibContainer->getByName( aLibName );
++        aLibAny >>= xLib;
++    }
++    if( xLib.is() )
++    {
++        if( xLib->hasByName( sModuleName ) )
++        {
++            xLib->removeByName( sModuleName );
++        }
++    }
++    SFX_APP()->LeaveBasicCall();
++}
++
+ 
+ BOOL ScDocFunc::InsertTable( SCTAB nTab, const String& rName, BOOL bRecord, BOOL bApi )
+ {
+@@ -2030,8 +2123,18 @@ BOOL ScDocFunc::InsertTable( SCTAB nTab,
+ 	ScDocShellModificator aModificator( rDocShell );
+ 
+ 	ScDocument* pDoc = rDocShell.GetDocument();
+-	if (bRecord && !pDoc->IsUndoEnabled())
++    // Strange loop, also basic is loaded too early ( InsertTable )
++    // is called via the xml import for sheets in described in odf 
++    BOOL bInsertDocModule = false;
++
++    if(  !rDocShell.GetDocument()->IsImportingXML() )
++    {
++        StarBASIC* pStarBASIC = rDocShell.GetBasic(); 
++        bInsertDocModule = pStarBASIC ? pStarBASIC->isVBAEnabled() : false;
++    }
++	if ( bInsertDocModule || ( bRecord && !pDoc->IsUndoEnabled() ) )
+ 		bRecord = FALSE;
++
+ 	if (bRecord)
+ 		pDoc->BeginDrawUndo();							//	InsertTab erzeugt ein SdrUndoNewPage
+ 
+@@ -2042,10 +2145,19 @@ BOOL ScDocFunc::InsertTable( SCTAB nTab,
+ 
+ 	if (pDoc->InsertTab( nTab, rName ))
+ 	{
++		String sCodeName;
+ 		if (bRecord)
+ 			rDocShell.GetUndoManager()->AddUndoAction(
+ 						new ScUndoInsertTab( &rDocShell, nTab, bAppend, rName));
+ 		//	Views updaten:
++        // Only insert vba modules if vba mode ( and not currently importing XML )
++        if( bInsertDocModule )
++        {
++            if ( sCodeName.Len() == 0 )
++		sCodeName = rName;
++            String sSource;
++            lcl_InsertModule( rDocShell, nTab, sCodeName, sSource );
++        }
+ 		rDocShell.Broadcast( ScTablesHint( SC_TAB_INSERTED, nTab ) );
+ 
+ 		rDocShell.PostPaintExtras();
+@@ -2067,8 +2179,12 @@ BOOL ScDocFunc::DeleteTable( SCTAB nTab,
+ 
+ 	BOOL bSuccess = FALSE;
+ 	ScDocument* pDoc = rDocShell.GetDocument();
++    StarBASIC* pStarBASIC = rDocShell.GetBasic();
++    BOOL bVbaEnabled = pStarBASIC->isVBAEnabled();
+ 	if (bRecord && !pDoc->IsUndoEnabled())
+ 		bRecord = FALSE;
++    if ( bVbaEnabled )
++        bRecord = FALSE;
+ 	BOOL bWasLinked = pDoc->IsLinked(nTab);
+ 	ScDocument* pUndoDoc = NULL;
+ 	ScRefUndoData* pUndoData = NULL;
+@@ -2109,6 +2225,8 @@ BOOL ScDocFunc::DeleteTable( SCTAB nTab,
+ 		pUndoData = new ScRefUndoData( pDoc );
+ 	}
+ 
++    String sCodeName;
++    BOOL bHasCodeName = pDoc->GetCodeName( nTab, sCodeName );
+ 	if (pDoc->DeleteTab( nTab, pUndoDoc ))
+ 	{
+ 		if (bRecord)
+@@ -2119,6 +2237,13 @@ BOOL ScDocFunc::DeleteTable( SCTAB nTab,
+ 						new ScUndoDeleteTab( &rDocShell, theTabs, pUndoDoc, pUndoData ));
+ 		}
+ 		//	Views updaten:
++        if( bVbaEnabled )
++        {
++            if( bHasCodeName )
++            {
++                lcl_DeleteModule( rDocShell, sCodeName );
++            }
++        }
+ 		rDocShell.Broadcast( ScTablesHint( SC_TAB_DELETED, nTab ) );
+ 
+ 		if (bWasLinked)
+diff --git sc/source/ui/docshell/docsh5.cxx sc/source/ui/docshell/docsh5.cxx
+index bbfe6e3..6623a4b 100644
+--- sc/source/ui/docshell/docsh5.cxx
++++ sc/source/ui/docshell/docsh5.cxx
+@@ -68,6 +68,11 @@
+ #include "sc.hrc"
+ #include "waitoff.hxx"
+ #include "sizedev.hxx"
++#include <basic/sbstar.hxx>
++#include <com/sun/star/script/ModuleSourceInfo.hpp>
++
++// defined in docfunc.cxx
++void lcl_InsertModule( ScDocShell& rDocSh, SCTAB nTab, String& sModuleName, String& sModuleSource );
+ 
+ // ---------------------------------------------------------------------------
+ 
+@@ -834,6 +839,33 @@ BOOL ScDocShell::MoveTable( SCTAB nSrcTa
+ 				GetUndoManager()->AddUndoAction(
+ 						new ScUndoCopyTab( this, aSrcList, aDestList ) );
+ 			}
++			
++			StarBASIC* pStarBASIC = GetBasic();
++			BOOL bVbaEnabled = pStarBASIC ? pStarBASIC->isVBAEnabled() : FALSE;
++			if ( bVbaEnabled )
++			{
++				String sCodeName;
++				String sSource;
++				aDocument.GetCodeName( nDestTab, sCodeName );
++				com::sun::star::uno::Reference< com::sun::star::script::XLibraryContainer > xLibContainer = GetBasicContainer();
++				com::sun::star::uno::Reference< com::sun::star::container::XNameContainer > xLib;
++    				if( xLibContainer.is() )
++    				{
++        				String aLibName( RTL_CONSTASCII_USTRINGPARAM( "Standard" ) );
++        				com::sun::star::uno::Any aLibAny = xLibContainer->getByName( aLibName );
++        				aLibAny >>= xLib;
++    				}
++    				if( xLib.is() )
++    				{
++					String sSrcCodeName;
++					aDocument.GetCodeName( nSrcTab, sSrcCodeName );
++					rtl::OUString sModName = sSrcCodeName;
++					com::sun::star::script::ModuleSourceInfo sModuleInfo;
++					xLib->getByName( sModName ) >>= sModuleInfo;
++					sSource = sModuleInfo.ModuleSource;
++				} 
++				lcl_InsertModule( *this, nDestTab, sCodeName, sSource );
++			}
+ 		}
+ 
+ 		Broadcast( ScTablesHint( SC_TAB_COPIED, nSrcTab, nDestTab ) );
+diff --git sc/source/ui/unoobj/servuno.cxx sc/source/ui/unoobj/servuno.cxx
+index bff687b..013c716 100644
+--- sc/source/ui/unoobj/servuno.cxx
++++ sc/source/ui/unoobj/servuno.cxx
+@@ -38,6 +38,7 @@
+ #include <svx/unofill.hxx>
+ #include <svx/unonrule.hxx>
+ #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
++#include <com/sun/star/container/XNameAccess.hpp>
+ 
+ #include "servuno.hxx"
+ #include "unonames.hxx"
+@@ -61,8 +62,103 @@
+ #include <svx/xmleohlp.hxx>
+ #include <svx/xmlgrhlp.hxx>
+ 
++#include <comphelper/processfactory.hxx>
++
+ using namespace ::com::sun::star;
+ 
++class ScVbaObjectForCodeNameProvider : public ::cppu::WeakImplHelper1< container::XNameAccess >
++{
++    uno::Any maWorkbook;
++    uno::Any maCachedObject;
++    uno::Reference<lang::XMultiServiceFactory> mxSF;
++    ScDocShell* mpDocShell;
++public:
++    ScVbaObjectForCodeNameProvider( ScDocShell* pDocShell ) : mpDocShell( pDocShell )
++    {
++        mxSF.set(comphelper::getProcessServiceFactory());
++        uno::Reference<beans::XPropertySet> xProps(mxSF, uno::UNO_QUERY);
++        if( xProps.is() )
++        {
++            ScDocument* pDoc = mpDocShell->GetDocument();
++            if ( !pDoc )
++                throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("")), uno::Reference< uno::XInterface >() );
++
++            uno::Sequence< uno::Any > aArgs(2);
++            aArgs[0] = uno::Any( uno::Reference< uno::XInterface >() );
++            aArgs[1] = uno::Any( mpDocShell->GetModel() );
++            maWorkbook <<= mxSF->createInstanceWithArguments(  rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("org.openoffice.excel.Workbook") ), aArgs );
++        }
++    }
++
++    virtual ::sal_Bool SAL_CALL hasByName( const ::rtl::OUString& aName ) throw (::com::sun::star::uno::RuntimeException )
++    {
++        maCachedObject = uno::Any(); // clear cached object
++        String sName = aName;
++        ScDocument* pDoc = mpDocShell->GetDocument();
++        if ( !pDoc )
++            throw uno::RuntimeException();
++        if ( sName == pDoc->GetCodeName() )
++            maCachedObject = maWorkbook;
++        else 
++        {
++            String sCodeName;
++            SCTAB nCount = pDoc->GetTableCount();
++            for( SCTAB i = 0; i < nCount; i++ )
++            {
++                pDoc->GetCodeName( i, sCodeName );
++                if( sCodeName == sName )
++                {
++                    String sSheetName;
++                    if( pDoc->GetName( i, sSheetName ) )
++                    {
++                        uno::Reference< frame::XModel > xModel( mpDocShell->GetModel() );
++                        uno::Reference <sheet::XSpreadsheetDocument> xSpreadDoc( xModel, uno::UNO_QUERY_THROW );
++                        uno::Reference<sheet::XSpreadsheets > xSheets( xSpreadDoc->getSheets(), uno::UNO_QUERY_THROW );
++                        uno::Reference< container::XIndexAccess > xIndexAccess( xSheets, uno::UNO_QUERY_THROW );
++                        uno::Reference< sheet::XSpreadsheet > xSheet( xIndexAccess->getByIndex( i ), uno::UNO_QUERY_THROW );
++                        uno::Sequence< uno::Any > aArgs(3);
++                        aArgs[0] = maWorkbook;
++                        aArgs[1] = uno::Any( xModel );
++                        aArgs[2] = uno::Any( rtl::OUString( sSheetName ) );
++                        maCachedObject <<= mxSF->createInstanceWithArguments(  rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("org.openoffice.excel.Worksheet") ), aArgs );
++                        break;
++                    }
++                }
++            }
++        }
++        return maCachedObject.hasValue();
++
++    }
++    ::com::sun::star::uno::Any SAL_CALL getByName( const ::rtl::OUString& aName ) throw (::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException)
++    {
++        OSL_TRACE("ScVbaObjectForCodeNameProvider::getByName( %s )",
++            rtl::OUStringToOString( aName, RTL_TEXTENCODING_UTF8 ).getStr() );
++        if ( !hasByName( aName ) )
++            throw ::com::sun::star::container::NoSuchElementException();
++        return maCachedObject;
++    }
++    virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getElementNames(  ) throw (::com::sun::star::uno::RuntimeException)
++    {
++        ScDocument* pDoc = mpDocShell->GetDocument();
++        if ( !pDoc )
++            throw uno::RuntimeException();
++        SCTAB nCount = pDoc->GetTableCount();
++        uno::Sequence< rtl::OUString > aNames( nCount + 1 ); 
++        SCTAB index = 0;
++        String sCodeName;
++        for( ; index < nCount; ++index )
++        {
++            pDoc->GetCodeName( index, sCodeName );
++            aNames[ index ] = sCodeName;
++        }
++        aNames[ index ] = pDoc->GetCodeName();
++        return aNames;
++    }
++    // XElemenAccess
++    virtual ::com::sun::star::uno::Type SAL_CALL getElementType(  ) throw (::com::sun::star::uno::RuntimeException){ return uno::Type(); }
++    virtual ::sal_Bool SAL_CALL hasElements(  ) throw (::com::sun::star::uno::RuntimeException ) { return sal_True; }
++
++};
+ 
+ //------------------------------------------------------------------------
+ 
+@@ -112,7 +208,8 @@ static const sal_Char* __FAR_DATA aProvN
+ 
+         SC_SERVICENAME_CHDATAPROV,                  // SC_SERVICE_CHDATAPROV
+         SC_SERVICENAME_FORMULAPARS,                 // SC_SERVICE_FORMULAPARS
+-        SC_SERVICENAME_OPCODEMAPPER                 // SC_SERVICE_OPCODEMAPPER
++        SC_SERVICENAME_OPCODEMAPPER,                 // SC_SERVICE_OPCODEMAPPER
++"org.openoffice.vba.VBAObjectModuleObjectProvider",// SC_SERVICE_VBAOBJECTPROVIDER
+ 	};
+ 
+ //
+@@ -164,7 +261,8 @@ static const sal_Char* __FAR_DATA aOldNa
+         "",                                         // SC_SERVICE_SHEETDOCSET
+         "",                                         // SC_SERVICE_CHDATAPROV
+         "",                                         // SC_SERVICE_FORMULAPARS
+-        ""                                          // SC_SERVICE_OPCODEMAPPER
++        "",                                         // SC_SERVICE_OPCODEMAPPER
++        "",                                         // SC_SERVICE_VBAOBJECTPROVIDER
+ 	};
+ 
+ 
+@@ -350,6 +448,9 @@ uno::Reference<uno::XInterface> ScServic
+         case SC_SERVICE_OPCODEMAPPER:
+             xRet.set(static_cast<sheet::XFormulaOpCodeMapper*>(new ScFormulaOpCodeMapperObj));
+             break;
++        case SC_SERVICE_VBAOBJECTPROVIDER:
++            xRet.set(static_cast<container::XNameAccess*>(new ScVbaObjectForCodeNameProvider( pDocShell )));
++            break;
+ 	}
+ 	return xRet;
+ }
+diff --git sc/source/ui/view/viewfun2.cxx sc/source/ui/view/viewfun2.cxx
+index 1ff1ec6..eace21b 100644
+--- sc/source/ui/view/viewfun2.cxx
++++ sc/source/ui/view/viewfun2.cxx
+@@ -57,6 +57,11 @@
+ #include <vcl/sound.hxx>
+ #include <vcl/waitobj.hxx>
+ 
++#include <basic/sbstar.hxx>
++#include <com/sun/star/container/XNameContainer.hpp>
++#include <com/sun/star/script/XLibraryContainer.hpp>
++using namespace com::sun::star;
++
+ #include "viewfunc.hxx"
+ 
+ #include "sc.hrc"
+@@ -2062,15 +2067,42 @@ BOOL ScViewFunc::DeleteTable( SCTAB nTab
+ 	return bSuccess;
+ }
+ 
++void lcl_DeleteModule( ScDocShell* rDocSh, String& sModuleName )
++{
++    SFX_APP()->EnterBasicCall();
++    uno::Reference< script::XLibraryContainer > xLibContainer = rDocSh->GetBasicContainer();
++    DBG_ASSERT( xLibContainer.is(), "No BasicContainer!" );
++
++    uno::Reference< container::XNameContainer > xLib;
++    if( xLibContainer.is() )
++    {
++        String aLibName( RTL_CONSTASCII_USTRINGPARAM( "Standard" ) );
++        uno::Any aLibAny = xLibContainer->getByName( aLibName );
++        aLibAny >>= xLib;
++    }
++    if( xLib.is() )
++    {
++        if( xLib->hasByName( sModuleName ) )
++        {
++            xLib->removeByName( sModuleName );
++        }
++    }
++    SFX_APP()->LeaveBasicCall();
++}
++
+ BOOL ScViewFunc::DeleteTables(const SvShorts &TheTabs, BOOL bRecord )
+ {
+ 	ScDocShell* pDocSh	= GetViewData()->GetDocShell();
+ 	ScDocument* pDoc 	= pDocSh->GetDocument();
++    StarBASIC* pStarBASIC = pDocSh->GetBasic();
++    BOOL bVbaEnabled = pStarBASIC->isVBAEnabled();
+ 	SCTAB		nNewTab = TheTabs[0];
+ 	int			i;
+ 	WaitObject aWait( GetFrameWin() );
+ 	if (bRecord && !pDoc->IsUndoEnabled())
+ 		bRecord = FALSE;
++    if ( bVbaEnabled )
++        bRecord = FALSE;
+ 
+ 	while ( nNewTab > 0 && !pDoc->IsVisible( nNewTab ) )
+ 		--nNewTab;
+@@ -2137,9 +2169,18 @@ BOOL ScViewFunc::DeleteTables(const SvSh
+ 
+ 	for(i=TheTabs.Count()-1;i>=0;i--)
+ 	{
++        String sCodeName;
++        BOOL bHasCodeName = pDoc->GetCodeName( TheTabs[sal::static_int_cast<USHORT>(i)], sCodeName );
+         if (pDoc->DeleteTab( TheTabs[sal::static_int_cast<USHORT>(i)], pUndoDoc ))
+ 		{
+ 			bDelDone = TRUE;
++            if( bVbaEnabled )
++            {
++                if( bHasCodeName )
++                {
++                    lcl_DeleteModule( pDocSh, sCodeName );
++                }
++            }
+             pDocSh->Broadcast( ScTablesHint( SC_TAB_DELETED, TheTabs[sal::static_int_cast<USHORT>(i)] ) );
+ 		}
+ 	}
+@@ -2167,6 +2208,7 @@ BOOL ScViewFunc::DeleteTables(const SvSh
+ 		pDocSh->PostPaintExtras();
+ 		pDocSh->SetDocumentModified();
+ 
++
+         SfxApplication* pSfxApp = SFX_APP();                                // Navigator
+         pSfxApp->Broadcast( SfxSimpleHint( SC_HINT_TABLES_CHANGED ) );
+         pSfxApp->Broadcast( SfxSimpleHint( SC_HINT_DBAREAS_CHANGED ) );
+diff --git svx/source/msfilter/msvbasic.cxx svx/source/msfilter/msvbasic.cxx
+index 2e4f500..2eff354 100644
+--- svx/source/msfilter/msvbasic.cxx
++++ svx/source/msfilter/msvbasic.cxx
+@@ -41,6 +41,8 @@
+ #include <rtl/tencinfo.h>   //rtl_getTextEncodingFromWindowsCodePage
+ #include "msvbasic.hxx"
+ 
++using namespace ::com::sun::star::script;
++
+ /*
+ A few urls which may in the future be of some use
+ http://www.virusbtn.com/vb2000/Programme/papers/bontchev.pdf
+@@ -432,7 +434,7 @@ int VBA_Impl::ReadVBAProject(const SvSto
+  *
+ */
+ 
+-ModuleType VBA_Impl::GetModuleType( const UniString& rModuleName )
++ModType VBA_Impl::GetModuleType( const UniString& rModuleName )
+ {
+     ModuleTypeHash::iterator iter = mhModHash.find( rModuleName );
+     ModuleTypeHash::iterator iterEnd = mhModHash.end();
+@@ -440,7 +442,7 @@ ModuleType VBA_Impl::GetModuleType( cons
+     {
+         return iter->second;
+     }
+-    return Unknown;
++    return ModuleType::Unknown;
+ }
+ 
+ bool VBA_Impl::Open( const String &rToplevel, const String &rSublevel )
+@@ -483,7 +485,7 @@ bool VBA_Impl::Open( const String &rTopl
+         static const String sClass(     RTL_CONSTASCII_USTRINGPARAM( "Class" ) );
+         static const String sBaseClass( RTL_CONSTASCII_USTRINGPARAM( "BaseClass" ) );
+         static const String sDocument(  RTL_CONSTASCII_USTRINGPARAM( "Document" ) );
+-        mhModHash[ sThisDoc ] = Class;
++        mhModHash[ sThisDoc ] = ModuleType::Class;
+         while ( pStp->ReadByteStringLine( tmp, meCharSet ) )
+         {
+             xub_StrLen index = tmp.Search( '=' );
+@@ -493,14 +495,14 @@ bool VBA_Impl::Open( const String &rTopl
+                 String value = tmp.Copy( index + 1 );
+                 if ( key == sClass )
+                 {
+-                    mhModHash[ value ] = Class;
++                    mhModHash[ value ] = ModuleType::Class;
+                     OSL_TRACE("Module %s is of type Class",
+                         ::rtl::OUStringToOString( value ,
+                             RTL_TEXTENCODING_ASCII_US ).pData->buffer );
+                 }
+                 else if ( key == sBaseClass )
+                 {
+-                    mhModHash[ value ] =  Form;
++                    mhModHash[ value ] =  ModuleType::Form;
+                     OSL_TRACE("Module %s is of type Form",
+                         ::rtl::OUStringToOString( value ,
+                             RTL_TEXTENCODING_ASCII_US ).pData->buffer );
+@@ -513,14 +515,14 @@ bool VBA_Impl::Open( const String &rTopl
+                     // value is of form <name>/&H<identifier>, strip the identifier
+                     value.Erase( value.Search( '/' ) );
+ 
+-                    mhModHash[ value ] = Document;
++                    mhModHash[ value ] = ModuleType::Document;
+                     OSL_TRACE("Module %s is of type Document VBA",
+                         ::rtl::OUStringToOString( value ,
+                             RTL_TEXTENCODING_ASCII_US ).pData->buffer );
+                 }
+                 else if ( key == sModule )
+                 {
+-                    mhModHash[ value ] = Normal;
++                    mhModHash[ value ] = ModuleType::Normal;
+                     OSL_TRACE("Module %s is of type Normal VBA",
+                         ::rtl::OUStringToOString( value ,
+                             RTL_TEXTENCODING_ASCII_US ).pData->buffer );
+diff --git svx/source/msfilter/msvbasic.hxx svx/source/msfilter/msvbasic.hxx
+index 8492062..a0536ae 100644
+--- svx/source/msfilter/msvbasic.hxx
++++ svx/source/msfilter/msvbasic.hxx
+@@ -45,6 +45,8 @@
+ #include <vector>
+ #endif
+ #include<map>
++#include <com/sun/star/script/ModuleType.hpp>
++using namespace ::com::sun::star::script::ModuleType;
+ 
+ /* class VBA:
+  * The VBA class provides a set of methods to handle Visual Basic For
+@@ -68,13 +70,12 @@ DECLARE_DYNARRAY(StringArray,String *)
+ // #117718# define internal types to distinguish between
+ // module types, form, class & normal
+ // #i37965# DR 2004-12-03: add "Document", used in Excel for macros attached to sheet
+-enum ModuleType { Unknown = 0, Normal, Class, Form, Document };
+ 
+ // #117718# define map to hold types of module
+ //
+-
++typedef sal_Int32 ModType;
+ typedef ::std::map< UniString,
+-    ModuleType > ModuleTypeHash;
++    ModType > ModuleTypeHash;
+ 
+ class VBA_Impl
+ {
+@@ -95,7 +96,7 @@ public:
+     void Output(int len, const sal_uInt8 *data);
+     //
+     // #117718# member map of module names to types of module
+-    ModuleType GetModuleType( const UniString& rModuleName );
++    ModType GetModuleType( const UniString& rModuleName );
+ 
+     std::vector<String> maReferences;
+ private:
+diff --git svx/source/msfilter/svxmsbas.cxx svx/source/msfilter/svxmsbas.cxx
+index d5878ad..df541c2 100644
+--- svx/source/msfilter/svxmsbas.cxx
++++ svx/source/msfilter/svxmsbas.cxx
+@@ -53,6 +53,9 @@ using namespace com::sun::star::awt;
+ 
+ #include <com/sun/star/container/XNameContainer.hpp>
+ #include <com/sun/star/script/XLibraryContainer.hpp>
++#include <com/sun/star/script/ModuleSourceInfo.hpp>
++#include <com/sun/star/script/XBasicLibraryInfo.hpp>
++
+ using namespace com::sun::star::container;
+ using namespace com::sun::star::script;
+ using namespace com::sun::star::uno;
+@@ -266,8 +269,26 @@ BOOL SvxImportMSVBasic::ImportCode_Impl(
+             Any aLibAny = xLibContainer->getByName( aLibName );
+ 		    aLibAny >>= xLib;
+         }
+-		if( xLib.is() )
++		if( xLib.is()  )
+ 		{
++            Reference< container::XNameAccess > xVBAObjectForCodeName;
++			if ( !bAsComment )
++            {
++                Reference< XBasicLibraryInfo > xInfo( xLib, UNO_QUERY );
++                if( xInfo.is() )
++                    xInfo->setVBACompatMode( sal_True );
++                else
++                    rDocSh.GetBasic()->SetVBAEnabled( true );
++                Reference< XMultiServiceFactory> xSF(rDocSh.GetModel(), UNO_QUERY);
++                if ( xSF.is() )
++                {
++                    try
++                    {
++                        xVBAObjectForCodeName.set( xSF->createInstance( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "org.openoffice.vba.VBAObjectModuleObjectProvider"))), UNO_QUERY );
++                    }
++                    catch( Exception& ) { }
++                }
++            }
+ 			for( UINT16 i=0; i<nStreamCount;i++)
+ 			{
+ 				StringArray aDecompressed = aVBA.Decompress(i);
+@@ -301,7 +322,7 @@ BOOL SvxImportMSVBasic::ImportCode_Impl(
+                 // is the same as the encoding for the names
+                 // that are keys in the map used by GetModuleType method
+                 const String &sOrigVBAModName = aVBA.GetStreamName( i );
+-                ModuleType mType = aVBA.GetModuleType( sOrigVBAModName );
++                ModType mType = aVBA.GetModuleType( sOrigVBAModName );
+ 
+                 rtl::OUString sClassRem( RTL_CONSTASCII_USTRINGPARAM( "Rem Attribute VBA_ModuleType=" ) );
+ 
+@@ -309,23 +330,23 @@ BOOL SvxImportMSVBasic::ImportCode_Impl(
+ 
+                 switch( mType )
+                 {
+-                    case Class:
++                    case ModuleType::Class:
+                         modeTypeComment = sClassRem +
+                             ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "VBAClassModule\n" ) );
+                         break;
+-                    case Form:
++                    case ModuleType::Form:
+                         modeTypeComment = sClassRem +
+                             ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "VBAFormModule\n" ) );
+                         break;
+-                    case Document:
++                    case ModuleType::Document:
+                         modeTypeComment = sClassRem +
+                             ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "VBADocumentModule\n" ) );
+                         break;
+-                    case Normal:
++                    case ModuleType::Normal:
+                         modeTypeComment = sClassRem +
+                             ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "VBAModule\n" ) );
+                         break;
+-                    case Unknown:
++                    case ModuleType::Unknown:
+                         modeTypeComment = sClassRem +
+                             ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "VBAUnknown\n" ) );
+                         break;
+@@ -335,10 +356,10 @@ BOOL SvxImportMSVBasic::ImportCode_Impl(
+                 }
+ 				static ::rtl::OUString sVBAOption( RTL_CONSTASCII_USTRINGPARAM( "Option VBASupport 1\n" ) ); 
+ 				static ::rtl::OUString sClassOption( RTL_CONSTASCII_USTRINGPARAM( "Option ClassModule\n" ) ); 
+-				if ( !bAsComment )
++				if ( !bAsComment /*&& !rDocSh.GetBasic()->isVBAEnabled() */)
+ 				{
+ 					modeTypeComment = modeTypeComment + sVBAOption;
+-					if ( mType == Class )
++					if ( mType == ModuleType::Class )
+ 						modeTypeComment = modeTypeComment + sClassOption;
+ 
+ 				}
+@@ -405,12 +426,41 @@ BOOL SvxImportMSVBasic::ImportCode_Impl(
+ 						aSource += rtl::OUString::createFromAscii("\nEnd Sub");
+ 				}
+ 				::rtl::OUString aModName( sModule );
+-				if ( aSource.getLength() )
+ 				{
+ 					aSource = modeTypeComment + aSource;
+ 
+ 					Any aSourceAny;
+-					aSourceAny <<= aSource;
++                    OSL_TRACE("erm %d", mType );
++                    if (  !bAsComment )
++                    {
++                        OSL_TRACE("vba processing  %d", mType );
++                        script::ModuleSourceInfo sModuleInfo;
++                        sModuleInfo.ModuleName = aModName;
++                        sModuleInfo.ModuleSource = aSource;
++                        sModuleInfo.ModuleType = mType;
++                       if ( mType == ModuleType::Form )
++                            // hack, the module ( imo document basic should...
++                            // know the XModel... ) but it doesn't
++                            sModuleInfo.ModuleObject.set( rDocSh.GetModel(), UNO_QUERY );
++			//  document modules, we should be able to access
++			//  the api objects at this time
++                        else if ( mType == ModuleType::Document )
++			{
++				uno::Reference< lang::XMultiServiceFactory> xSF( rDocSh.GetModel(), uno::UNO_QUERY);
++				uno::Reference< container::XNameAccess > xVBACodeNamedObjectAccess;
++    				if ( xSF.is() )
++				        xVBACodeNamedObjectAccess.set( xSF->createInstance( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "org.openoffice.vba.VBAObjectModuleObjectProvider"))), uno::UNO_QUERY );    
++				// get the api object for the codename
++				if ( xVBACodeNamedObjectAccess.is() )
++				{
++					sModuleInfo.ModuleObject.set( xVBACodeNamedObjectAccess->getByName( sModuleInfo.ModuleName ), uno::UNO_QUERY );    
++					OSL_TRACE("** Straight up creation of Module");
++				}
++			}
++                        aSourceAny <<= sModuleInfo;
++                    }
++                    else
++					    aSourceAny <<= aSource;
+ 					if( xLib->hasByName( aModName ) )
+ 						xLib->replaceByName( aModName, aSourceAny );
+ 					else
+@@ -420,6 +470,7 @@ BOOL SvxImportMSVBasic::ImportCode_Impl(
+ 				bRet = true;
+ 			}
+ 		}
++        if( bRet )
+ 		SFX_APP()->LeaveBasicCall();
+ 	}
+ 	return bRet;
+diff --git udkapi/com/sun/star/script/ModuleInfo.idl udkapi/com/sun/star/script/ModuleInfo.idl
+new file mode 100644
+index 0000000..d670ec6
+--- /dev/null
++++ udkapi/com/sun/star/script/ModuleInfo.idl
+@@ -0,0 +1,56 @@
++/*************************************************************************
++ *
++ *  OpenOffice.org - a multi-platform office productivity suite
++ *
++ *  $RCSfile: ModuleInfo.idl,v $
++ *
++ *  $Revision: 1.2 $
++ *
++ *  last change: $Author: rt $ $Date: 2006/05/05 10:14:46 $
++ *
++ *  The Contents of this file are made available subject to
++ *  the terms of GNU Lesser General Public License Version 2.1.
++ *
++ *
++ *    GNU Lesser General Public License Version 2.1
++ *    =============================================
++ *    Copyright 2005 by Sun Microsystems, Inc.
++ *    901 San Antonio Road, Palo Alto, CA 94303, USA
++ *
++ *    This library is free software; you can redistribute it and/or
++ *    modify it under the terms of the GNU Lesser General Public
++ *    License version 2.1, as published by the Free Software Foundation.
++ *
++ *    This library is distributed in the hope that it will be useful,
++ *    but WITHOUT ANY WARRANTY; without even the implied warranty of
++ *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
++ *    Lesser General Public License for more details.
++ *
++ *    You should have received a copy of the GNU Lesser General Public
++ *    License along with this library; if not, write to the Free Software
++ *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
++ *    MA  02111-1307  USA
++ *
++ ************************************************************************/
++
++#ifndef __com_sun_star_script_ModuleInfo_idl__
++#define __com_sun_star_script_ModuleInfo_idl__
++
++#ifndef __com_sun_star_uno_XInterface_idl__
++#include <com/sun/star/uno/XInterface.idl>
++#endif
++
++//=============================================================================
++module com {  module sun {  module star { module script {
++struct ModuleInfo
++{
++	string ModuleName; 
++	com::sun::star::uno::XInterface ModuleObject; 
++	short ModuleType; // string?
++};
++
++//=============================================================================
++
++}; }; }; };
++
++#endif
+diff --git udkapi/com/sun/star/script/ModuleSourceInfo.idl udkapi/com/sun/star/script/ModuleSourceInfo.idl
+new file mode 100644
+index 0000000..feef569
+--- /dev/null
++++ udkapi/com/sun/star/script/ModuleSourceInfo.idl
+@@ -0,0 +1,57 @@
++/*************************************************************************
++ *
++ *  OpenOffice.org - a multi-platform office productivity suite
++ *
++ *  $RCSfile: ModuleInfo.idl,v $
++ *
++ *  $Revision: 1.2 $
++ *
++ *  last change: $Author: rt $ $Date: 2006/05/05 10:14:46 $
++ *
++ *  The Contents of this file are made available subject to
++ *  the terms of GNU Lesser General Public License Version 2.1.
++ *
++ *
++ *    GNU Lesser General Public License Version 2.1
++ *    =============================================
++ *    Copyright 2005 by Sun Microsystems, Inc.
++ *    901 San Antonio Road, Palo Alto, CA 94303, USA
++ *
++ *    This library is free software; you can redistribute it and/or
++ *    modify it under the terms of the GNU Lesser General Public
++ *    License version 2.1, as published by the Free Software Foundation.
++ *
++ *    This library is distributed in the hope that it will be useful,
++ *    but WITHOUT ANY WARRANTY; without even the implied warranty of
++ *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
++ *    Lesser General Public License for more details.
++ *
++ *    You should have received a copy of the GNU Lesser General Public
++ *    License along with this library; if not, write to the Free Software
++ *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
++ *    MA  02111-1307  USA
++ *
++ ************************************************************************/
++
++#ifndef __com_sun_star_script_ModuleSourceInfo_idl__
++#define __com_sun_star_script_ModuleSourceInfo_idl__
++
++#ifndef __com_sun_star_uno_XInterface_idl__
++#include <com/sun/star/uno/XInterface.idl>
++#endif
++#ifndef __com_sun_star_script_ModuleInfo_idl__
++#include <com/sun/star/script/ModuleInfo.idl>
++#endif
++
++//=============================================================================
++module com {  module sun {  module star { module script {
++struct ModuleSourceInfo : ModuleInfo
++{
++	string ModuleSource; 
++};
++
++//=============================================================================
++
++}; }; }; };
++
++#endif
+diff --git udkapi/com/sun/star/script/ModuleType.idl udkapi/com/sun/star/script/ModuleType.idl
+new file mode 100644
+index 0000000..3295c52
+--- /dev/null
++++ udkapi/com/sun/star/script/ModuleType.idl
+@@ -0,0 +1,58 @@
++/*************************************************************************
++ *
++ *  OpenOffice.org - a multi-platform office productivity suite
++ *
++ *  $RCSfile: ModuleType.idl,v $
++ *
++ *  $Revision: 1.2 $
++ *
++ *  last change: $Author: rt $ $Date: 2006/05/05 10:14:46 $
++ *
++ *  The Contents of this file are made available subject to
++ *  the terms of GNU Lesser General Public License Version 2.1.
++ *
++ *
++ *    GNU Lesser General Public License Version 2.1
++ *    =============================================
++ *    Copyright 2005 by Sun Microsystems, Inc.
++ *    901 San Antonio Road, Palo Alto, CA 94303, USA
++ *
++ *    This library is free software; you can redistribute it and/or
++ *    modify it under the terms of the GNU Lesser General Public
++ *    License version 2.1, as published by the Free Software Foundation.
++ *
++ *    This library is distributed in the hope that it will be useful,
++ *    but WITHOUT ANY WARRANTY; without even the implied warranty of
++ *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
++ *    Lesser General Public License for more details.
++ *
++ *    You should have received a copy of the GNU Lesser General Public
++ *    License along with this library; if not, write to the Free Software
++ *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
++ *    MA  02111-1307  USA
++ *
++ ************************************************************************/
++
++#ifndef __com_sun_star_script_ModuleType_idl__
++#define __com_sun_star_script_ModuleType_idl__
++
++#ifndef __com_sun_star_uno_XInterface_idl__
++#include <com/sun/star/uno/XInterface.idl>
++#endif
++
++//=============================================================================
++module com {  module sun {  module star { module script {
++published constants ModuleType
++{
++    const long Unknown = 0;
++    const long Normal = 1;  
++    const long Class = 2;
++    const long Form = 3;
++    const long Document = 4;
++};
++
++//=============================================================================
++
++}; }; }; };
++
++#endif
+diff --git udkapi/com/sun/star/script/makefile.mk udkapi/com/sun/star/script/makefile.mk
+index 745df3e..d36f19d 100644
+--- udkapi/com/sun/star/script/makefile.mk
++++ udkapi/com/sun/star/script/makefile.mk
+@@ -85,6 +85,9 @@ IDLFILES=\
+ 	XScriptEventsAttacher.idl\
+ 	XDefaultMethod.idl\
+ 	XDefaultProperty.idl\
++    ModuleInfo.idl\
++    ModuleType.idl\
++    ModuleSourceInfo.idl\
+ 
+ # ------------------------------------------------------------------
+ 

Added: trunk/patches/vba/native-export/basic-ide-module-object-name-combile.diff
==============================================================================
--- (empty file)
+++ trunk/patches/vba/native-export/basic-ide-module-object-name-combile.diff	Wed Oct 29 15:27:45 2008
@@ -0,0 +1,105 @@
+diff --git basctl/source/basicide/basides2.cxx basctl/source/basicide/basides2.cxx
+index 90cec19..c647b89 100644
+--- basctl/source/basicide/basides2.cxx
++++ basctl/source/basicide/basides2.cxx
+@@ -55,11 +55,34 @@
+ #include <tools/diagnose_ex.h>
+ #include <sfx2/sfxdefs.hxx>
+ #include <sfx2/signaturestate.hxx>
++#include <com/sun/star/script/XBasicLibraryInfo.hpp>
++#include <com/sun/star/container/XNameContainer.hpp>
++#include <com/sun/star/container/XNamed.hpp>
++#include <com/sun/star/lang/XServiceInfo.hpp>
+ 
+ using namespace ::com::sun::star;
+ using namespace ::com::sun::star::uno;
+ namespace css = ::com::sun::star;
+ 
++void lcl_getObjectName( const uno::Reference< container::XNameContainer >& rLib, const String& rModName, String& rObjName )
++{
++	uno::Any aElement( rLib->getByName( rModName ) );
++	script::ModuleInfo aModuleInfo;
++	Reference< script::XBasicLibraryInfo > xLibInfo( rLib, UNO_QUERY );
++	if ( xLibInfo.is() && xLibInfo->getVBACompatMode() )
++	{
++		script::ModuleInfo aModuleInfo = xLibInfo->getModuleInfo( rModName );
++		uno::Reference< lang::XServiceInfo > xServiceInfo( aModuleInfo.ModuleObject, uno::UNO_QUERY );
++
++		if( xServiceInfo.is() && xServiceInfo->supportsService( rtl::OUString::createFromAscii( "org.openoffice.excel.Worksheet" ) ) )
++		{
++			uno::Reference< container::XNamed > xNamed( aModuleInfo.ModuleObject, uno::UNO_QUERY );
++			if( xNamed.is() )
++				rObjName = xNamed->getName();
++		}
++	}	
++}
++
+ IMPL_LINK_INLINE_START( BasicIDEShell, ObjectDialogCancelHdl, ObjectCatalog *, EMPTYARG )
+ {
+ 	ShowObjectDialog( FALSE, TRUE );
+@@ -232,7 +255,7 @@ ModulWindow* BasicIDEShell::CreateBasWin
+     if ( !aLibName.Len() )
+         aLibName = String::CreateFromAscii( "Standard" );
+ 
+-    rDocument.getOrCreateLibrary( E_SCRIPTS, aLibName );
++    uno::Reference< container::XNameContainer > xLib = rDocument.getOrCreateLibrary( E_SCRIPTS, aLibName );
+ 
+ 	if ( !aModName.Len() )
+         aModName = rDocument.createObjectName( E_SCRIPTS, aLibName );
+@@ -272,7 +295,20 @@ ModulWindow* BasicIDEShell::CreateBasWin
+ 		DBG_ASSERT( nKey, "CreateBasWin: Kein Key- Fenster nicht gefunden!" );
+ 	}
+     if( nKey )
++	{
++		if( xLib.is() )
++		{
++			// display a nice friendly name in the ObjectModule tab,
++			// combining the objectname and module name, e.g. Sheet1 ( Financials )
++			String sObjName;
++			lcl_getObjectName( xLib, rModName, sObjName );
++			if( sObjName.Len() )
++			{
++				aModName.AppendAscii(" (").Append(sObjName).AppendAscii(")");
++			}
++		}
+ 	    pTabBar->InsertPage( (USHORT)nKey, aModName );
++	}	
+ 	pTabBar->Sort();
+ 	pWin->GrabScrollBars( &aHScrollBar, &aVScrollBar );
+ 	if ( !pCurWin )
+diff --git oovbaapi/org/openoffice/excel/XWorksheet.idl oovbaapi/org/openoffice/excel/XWorksheet.idl
+index 3a9ad3e..3b39f1e 100644
+--- oovbaapi/org/openoffice/excel/XWorksheet.idl
++++ oovbaapi/org/openoffice/excel/XWorksheet.idl
+@@ -42,6 +42,9 @@
+ #include <com/sun/star/script/XInvocation.idl>
+ #endif
+ 
++#ifndef __com_sun_star_container_XNamed_idl__
++#include <com/sun/star/container/XNamed.idl>
++#endif
+ //=============================================================================
+ 
+ module org {  module openoffice {  module excel { 
+@@ -57,8 +60,8 @@ interface XWorksheet
+ {
+ 	interface ::org::openoffice::vba::XHelperInterface;
+ 	interface ::com::sun::star::script::XInvocation;
++	interface ::com::sun::star::container::XNamed;
+ 
+-	[attribute] string Name;
+ 	[attribute] boolean Visible; 
+ 	[attribute, readonly] long StandardHeight;
+ 	[attribute, readonly] long StandardWidth;
+diff --git sc/source/ui/vba/vbaworksheet.hxx sc/source/ui/vba/vbaworksheet.hxx
+index 991d46c..9670820 100644
+--- sc/source/ui/vba/vbaworksheet.hxx
++++ sc/source/ui/vba/vbaworksheet.hxx
+@@ -45,6 +45,7 @@
+ #include <org/openoffice/excel/XPageSetup.hpp>
+ #include <org/openoffice/excel/XHPageBreaks.hpp>
+ #include <org/openoffice/excel/XChartObjects.hpp>
++#include <com/sun/star/container/XNamed.hpp>
+ 
+ #include "vbahelperinterface.hxx"
+ 

Added: trunk/patches/vba/native-export/vba-basic-macrochoose-dialog.diff
==============================================================================
--- (empty file)
+++ trunk/patches/vba/native-export/vba-basic-macrochoose-dialog.diff	Wed Oct 29 15:27:45 2008
@@ -0,0 +1,842 @@
+diff --git basctl/inc/basidesh.hrc basctl/inc/basidesh.hrc
+index a4e944b..0064b1f 100644
+--- basctl/inc/basidesh.hrc
++++ basctl/inc/basidesh.hrc
+@@ -175,6 +175,10 @@
+ #define RID_STR_EXPORTPACKAGE			( RID_BASICIDE_START + 100 )
+ #define RID_STR_EXPORTBASIC				( RID_BASICIDE_START + 101 )
+ #define RID_STR_PACKAGE_BUNDLE			( RID_BASICIDE_START + 102 )
++#define RID_STR_DOCUMENT_OBJECTS        ( RID_BASICIDE_START + 110 )
++#define RID_STR_USERFORMS               ( RID_BASICIDE_START + 111 )
++#define RID_STR_NORMAL_MODULES          ( RID_BASICIDE_START + 112 )
++#define RID_STR_CLASS_MODULES           ( RID_BASICIDE_START + 113 )
+ 
+ #endif	// _SVX_NOIDERESIDS
+ 
+diff --git basctl/source/basicide/baside2.cxx basctl/source/basicide/baside2.cxx
+index a1e47ed..78a276b 100644
+--- basctl/source/basicide/baside2.cxx
++++ basctl/source/basicide/baside2.cxx
+@@ -49,6 +49,7 @@
+ #include <com/sun/star/script/XLibraryContainer2.hpp>
+ #endif
+ #include <com/sun/star/document/MacroExecMode.hpp>
++#include <com/sun/star/script/ModuleType.hpp>
+ #include <toolkit/helper/vclunohelper.hxx>
+ #include <sfx2/docfile.hxx>
+ #include <basic/basrdll.hxx>
+@@ -110,6 +111,8 @@ DBG_NAME( ModulWindow )
+ 
+ TYPEINIT1( ModulWindow , IDEBaseWindow );
+ 
++void lcl_getObjectName( const uno::Reference< container::XNameContainer >& rLib, const String& rModName, String& rObjName );
++
+ void lcl_PrintHeader( Printer* pPrinter, USHORT nPages, USHORT nCurPage, const String& rTitle )
+ {
+ 	short nLeftMargin 	= LMARGPRN;
+@@ -1347,7 +1350,39 @@ BasicEntryDescriptor ModulWindow::Create
+     ScriptDocument aDocument( GetDocument() );
+     String aLibName( GetLibName() );
+     LibraryLocation eLocation = aDocument.getLibraryLocation( aLibName );
+-    return BasicEntryDescriptor( aDocument, eLocation, aLibName, GetName(), OBJ_TYPE_MODULE );
++    String aModName( GetName() );
++    String aLibSubName;
++    if( xBasic.Is() && xBasic->isVBAEnabled() && xModule.Is() )
++    {
++        switch( xModule->GetModuleType() )
++        {
++            case script::ModuleType::Document:
++            {
++                aLibSubName = String( IDEResId( RID_STR_DOCUMENT_OBJECTS ) );
++                uno::Reference< container::XNameContainer > xLib = aDocument.getOrCreateLibrary( E_SCRIPTS, aLibName );
++                if( xLib.is() )
++                {
++                    String sObjName;
++                    lcl_getObjectName( xLib, aModName, sObjName );
++                    if( sObjName.Len() )
++                    {
++                        aModName.AppendAscii(" (").Append(sObjName).AppendAscii(")");
++                    }
++                }
++                break;
++            }    
++            case script::ModuleType::Form:
++                aLibSubName = String( IDEResId( RID_STR_USERFORMS ) );
++                break;
++            case script::ModuleType::Normal:
++                aLibSubName = String( IDEResId( RID_STR_NORMAL_MODULES ) );
++                break;
++            case script::ModuleType::Class:
++                aLibSubName = String( IDEResId( RID_STR_CLASS_MODULES ) );
++                break;
++        }
++    }
++    return BasicEntryDescriptor( aDocument, eLocation, aLibName, aLibSubName, aModName, OBJ_TYPE_MODULE );
+ }
+ 
+ void ModulWindow::SetReadOnly( BOOL b )
+diff --git basctl/source/basicide/baside3.cxx basctl/source/basicide/baside3.cxx
+index 12c8e0c..e89c22f 100644
+--- basctl/source/basicide/baside3.cxx
++++ basctl/source/basicide/baside3.cxx
+@@ -894,8 +894,9 @@ BasicEntryDescriptor DialogWindow::Creat
+ {
+     ScriptDocument aDocument( GetDocument() );
+     String aLibName( GetLibName() );
++    String aLibSubName;
+     LibraryLocation eLocation = aDocument.getLibraryLocation( aLibName );
+-    return BasicEntryDescriptor( aDocument, eLocation, aLibName, GetName(), OBJ_TYPE_DIALOG );
++    return BasicEntryDescriptor( aDocument, eLocation, aLibName, aLibSubName, GetName(), OBJ_TYPE_DIALOG );
+ }
+ 
+ void DialogWindow::SetReadOnly( BOOL b )
+diff --git basctl/source/basicide/basidesh.src basctl/source/basicide/basidesh.src
+index f02f914..9ee8434 100644
+--- basctl/source/basicide/basidesh.src
++++ basctl/source/basicide/basidesh.src
+@@ -639,6 +639,22 @@ String RID_STR_TRANSLATION_DEFAULT
+ {
+ 	Text [ en-US ] = "[Default Language]" ;
+ };
++String RID_STR_DOCUMENT_OBJECTS
++{
++    Text [ en-US ] = "Document Objects" ;
++};
++String RID_STR_USERFORMS
++{
++    Text [ en-US ] = "Forms" ;
++};
++String RID_STR_NORMAL_MODULES
++{
++    Text [ en-US ] = "Modules" ;
++};
++String RID_STR_CLASS_MODULES
++{
++    Text [ en-US ] = "Class Modules" ;
++};
+ 
+ #define MN_EDIT       20
+ #define MN_VIEW 21
+diff --git basctl/source/basicide/bastype2.cxx basctl/source/basicide/bastype2.cxx
+index 7754d71..94a981c 100644
+--- basctl/source/basicide/bastype2.cxx
++++ basctl/source/basicide/bastype2.cxx
+@@ -53,10 +53,27 @@
+ #include <com/sun/star/frame/XModuleManager.hpp>
+ #include <comphelper/processfactory.hxx>
+ #include <comphelper/componentcontext.hxx>
++#include <map>
++#include <com/sun/star/script/ModuleType.hpp>
++#include <com/sun/star/script/XBasicLibraryInfo.hpp>
++#include <com/sun/star/container/XNameContainer.hpp>
+ 
+ using namespace ::com::sun::star::uno;
+ using namespace ::com::sun::star;
+ 
++void lcl_getObjectName( const uno::Reference< container::XNameContainer >& rLib, const String& rModName, String& rObjName );
++
++sal_Int32 lcl_getModuleType(  const uno::Reference< container::XNameContainer >& rLib, const String& rModName )
++{
++    sal_Int32 nType = com::sun::star::script::ModuleType::Unknown;
++    Reference< script::XBasicLibraryInfo > xLibInfo( rLib, UNO_QUERY );
++    if ( xLibInfo.is() && xLibInfo->getVBACompatMode() )
++    {
++        script::ModuleInfo aModuleInfo = xLibInfo->getModuleInfo( rModName );
++        nType = aModuleInfo.ModuleType;
++    }
++    return nType;    
++}
+ 
+ BasicEntry::~BasicEntry()
+ {
+@@ -91,20 +108,22 @@ BasicEntryDescriptor::BasicEntryDescript
+ {
+ }
+ 
+-BasicEntryDescriptor::BasicEntryDescriptor( const ScriptDocument& rDocument, LibraryLocation eLocation, const String& rLibName, const String& rName, BasicEntryType eType )
++BasicEntryDescriptor::BasicEntryDescriptor( const ScriptDocument& rDocument, LibraryLocation eLocation, const String& rLibName, const String& rLibSubName, const String& rName, BasicEntryType eType )
+     :m_aDocument( rDocument )
+     ,m_eLocation( eLocation )
+     ,m_aLibName( rLibName )
++    ,m_aLibSubName( rLibSubName )
+     ,m_aName( rName )
+     ,m_eType( eType )
+ {
+     OSL_ENSURE( m_aDocument.isValid(), "BasicEntryDescriptor::BasicEntryDescriptor: invalid document!" );
+ }
+ 
+-BasicEntryDescriptor::BasicEntryDescriptor( const ScriptDocument& rDocument, LibraryLocation eLocation, const String& rLibName, const String& rName, const String& rMethodName, BasicEntryType eType )
++BasicEntryDescriptor::BasicEntryDescriptor( const ScriptDocument& rDocument, LibraryLocation eLocation, const String& rLibName, const String& rLibSubName, const String& rName, const String& rMethodName, BasicEntryType eType )
+     :m_aDocument( rDocument )
+     ,m_eLocation( eLocation )
+     ,m_aLibName( rLibName )
++    ,m_aLibSubName( rLibSubName )
+     ,m_aName( rName )
+     ,m_aMethodName( rMethodName )
+     ,m_eType( eType )
+@@ -120,6 +139,7 @@ BasicEntryDescriptor::BasicEntryDescript
+     :m_aDocument( rDesc.m_aDocument )
+     ,m_eLocation( rDesc.m_eLocation )
+     ,m_aLibName( rDesc.m_aLibName )
++    ,m_aLibSubName( rDesc.m_aLibSubName )
+     ,m_aName( rDesc.m_aName )
+     ,m_aMethodName( rDesc.m_aMethodName )
+     ,m_eType( rDesc.m_eType )
+@@ -131,6 +151,7 @@ BasicEntryDescriptor& BasicEntryDescript
+     m_aDocument = rDesc.m_aDocument;
+     m_eLocation = rDesc.m_eLocation;
+     m_aLibName = rDesc.m_aLibName;
++    m_aLibSubName = rDesc.m_aLibSubName;
+     m_aName = rDesc.m_aName;
+     m_aMethodName = rDesc.m_aMethodName;
+     m_eType = rDesc.m_eType;
+@@ -143,6 +164,7 @@ bool BasicEntryDescriptor::operator==( c
+     return m_aDocument == rDesc.m_aDocument &&
+            m_eLocation == rDesc.m_eLocation &&
+            m_aLibName == rDesc.m_aLibName &&
++           m_aLibSubName == rDesc.m_aLibSubName &&
+            m_aName == rDesc.m_aName &&
+            m_aMethodName == rDesc.m_aMethodName &&
+            m_eType == rDesc.m_eType;
+@@ -286,50 +308,58 @@ void BasicTreeListBox::ImpCreateLibSubEn
+         if ( xModLibContainer.is() && xModLibContainer->hasByName( aOULibName ) && xModLibContainer->isLibraryLoaded( aOULibName ) )
+         {
+             try
+-		    {
+-                // get a sorted list of module names
+-                Sequence< ::rtl::OUString > aModNames = rDocument.getObjectNames( E_SCRIPTS, rLibName );
+-                sal_Int32 nModCount = aModNames.getLength();
+-	            const ::rtl::OUString* pModNames = aModNames.getConstArray();
+-
+-                for ( sal_Int32 i = 0 ; i < nModCount ; i++ )
+-				{
+-                    String aModName = pModNames[ i ];
+-                    SvLBoxEntry* pModuleEntry = FindEntry( pLibRootEntry, aModName, OBJ_TYPE_MODULE );
+-                    if ( !pModuleEntry )
+-                        pModuleEntry = AddEntry(
+-                            aModName,
+-                            Image( IDEResId( RID_IMG_MODULE ) ),
+-                            Image( IDEResId( RID_IMG_MODULE_HC ) ),
+-                            pLibRootEntry, false,
+-                            std::auto_ptr< BasicEntry >( new BasicEntry( OBJ_TYPE_MODULE ) ) );
+-
+-					// methods
+-					if ( nMode & BROWSEMODE_SUBS )
+-					{
+-                        Sequence< ::rtl::OUString > aNames = BasicIDE::GetMethodNames( rDocument, rLibName, aModName );
+-						sal_Int32 nCount = aNames.getLength();
+-						const ::rtl::OUString* pNames = aNames.getConstArray();
+-
+-						for ( sal_Int32 j = 0 ; j < nCount ; j++ )
+-						{
+-							String aName = pNames[ j ];
+-							SvLBoxEntry* pEntry = FindEntry( pModuleEntry, aName, OBJ_TYPE_METHOD );
+-                            if ( !pEntry )
+-                                pEntry = AddEntry(
+-                                    aName,
+-                                    Image( IDEResId( RID_IMG_MACRO ) ),
+-                                    Image( IDEResId( RID_IMG_MACRO_HC ) ),
+-                                    pModuleEntry, false,
+-                                    std::auto_ptr< BasicEntry >( new BasicEntry( OBJ_TYPE_METHOD ) ) );
+-						}
+-                    }
+-				}
++		 	{
++                BasicManager* pBasMgr = rDocument.getBasicManager();
++                StarBASIC* pBasic = pBasMgr ? pBasMgr->GetLib( rLibName ) : 0;
++                sal_Bool bVBAEnabled = pBasic ? pBasic->isVBAEnabled(): sal_False;
++                if( bVBAEnabled )
++                    ImpCreateLibSubEntriesInVBAMode( pLibRootEntry, rDocument, rLibName );
++                else
++                {
++                    // get a sorted list of module names
++                    Sequence< ::rtl::OUString > aModNames = rDocument.getObjectNames( E_SCRIPTS, rLibName );
++                    sal_Int32 nModCount = aModNames.getLength();
++		            const ::rtl::OUString* pModNames = aModNames.getConstArray();
++
++                    for ( sal_Int32 i = 0 ; i < nModCount ; i++ )
++		 			{
++                        String aModName = pModNames[ i ];
++                        SvLBoxEntry* pModuleEntry = FindEntry( pLibRootEntry, aModName, OBJ_TYPE_MODULE );
++                        if ( !pModuleEntry )
++                            pModuleEntry = AddEntry(
++                                aModName,
++                                Image( IDEResId( RID_IMG_MODULE ) ),
++                                Image( IDEResId( RID_IMG_MODULE_HC ) ),
++                                pLibRootEntry, false,
++                                std::auto_ptr< BasicEntry >( new BasicEntry( OBJ_TYPE_MODULE ) ) );
++
++		 				// methods
++		 				if ( nMode & BROWSEMODE_SUBS )
++		 				{
++                            Sequence< ::rtl::OUString > aNames = BasicIDE::GetMethodNames( rDocument, rLibName, aModName );
++		 					sal_Int32 nCount = aNames.getLength();
++		 					const ::rtl::OUString* pNames = aNames.getConstArray();
++
++		 					for ( sal_Int32 j = 0 ; j < nCount ; j++ )
++		 					{
++		 						String aName = pNames[ j ];
++		 						SvLBoxEntry* pEntry = FindEntry( pModuleEntry, aName, OBJ_TYPE_METHOD );
++                                if ( !pEntry )
++                                    pEntry = AddEntry(
++                                        aName,
++                                        Image( IDEResId( RID_IMG_MACRO ) ),
++                                        Image( IDEResId( RID_IMG_MACRO_HC ) ),
++                                        pModuleEntry, false,
++                                        std::auto_ptr< BasicEntry >( new BasicEntry( OBJ_TYPE_METHOD ) ) );
++		 					}
++                        }
++		 			}
++                }
+             }
+-		    catch ( const container::NoSuchElementException& )
+-		    {
++		 	catch ( const container::NoSuchElementException& )
++		 	{
+                 DBG_UNHANDLED_EXCEPTION();
+-		    }
++		 	}
+         }   
+     }
+ 
+@@ -368,6 +398,139 @@ void BasicTreeListBox::ImpCreateLibSubEn
+     }
+ }
+ 
++void BasicTreeListBox::ImpCreateLibSubEntriesInVBAMode( SvLBoxEntry* pLibRootEntry, const ScriptDocument& rDocument, const String& rLibName )
++{
++    ::std::map< BasicEntryType, ::rtl::OUString > aEntryMap;
++    aEntryMap.insert( ::std::make_pair( OBJ_TYPE_DOCUMENT_OBJECTS, String( IDEResId( RID_STR_DOCUMENT_OBJECTS ) ) ) );
++    aEntryMap.insert( ::std::make_pair( OBJ_TYPE_USERFORMS,  String( IDEResId( RID_STR_USERFORMS ) ) ) );
++    aEntryMap.insert( ::std::make_pair( OBJ_TYPE_NORMAL_MODULES, String( IDEResId( RID_STR_NORMAL_MODULES ) ) ) );
++    aEntryMap.insert( ::std::make_pair( OBJ_TYPE_CLASS_MODULES,  String( IDEResId( RID_STR_CLASS_MODULES ) ) ) );
++
++    ::std::map< BasicEntryType, ::rtl::OUString >::iterator iter;
++    for( iter = aEntryMap.begin(); iter != aEntryMap.end(); ++iter )
++    {
++        BasicEntryType eType = iter->first;
++        ::rtl::OUString aEntryName = iter->second;
++        SvLBoxEntry* pLibSubRootEntry = FindEntry( pLibRootEntry, aEntryName, eType );
++        if( pLibSubRootEntry )
++        {
++            SetEntryBitmaps( pLibSubRootEntry, Image( IDEResId( RID_IMG_MODLIB ) ), Image( IDEResId( RID_IMG_MODLIB_HC ) ) );
++            if ( IsExpanded( pLibSubRootEntry ) )
++			    ImpCreateLibSubSubEntriesInVBAMode( pLibSubRootEntry, rDocument, rLibName );
++        }
++        else
++        {
++            pLibSubRootEntry = AddEntry(
++                aEntryName,
++                Image( IDEResId( RID_IMG_MODLIB ) ),
++                Image( IDEResId( RID_IMG_MODLIB_HC ) ),
++                pLibRootEntry, true,
++                std::auto_ptr< BasicEntry >( new BasicEntry( eType ) ) );
++        }
++    }
++}
++
++void BasicTreeListBox::ImpCreateLibSubSubEntriesInVBAMode( SvLBoxEntry* pLibSubRootEntry, const ScriptDocument& rDocument, const String& rLibName )
++{
++    uno::Reference< container::XNameContainer > xLib = rDocument.getOrCreateLibrary( E_SCRIPTS, rLibName );
++    if( !xLib.is() )
++        return;
++
++    try
++	{
++        // get a sorted list of module names
++        Sequence< ::rtl::OUString > aModNames = rDocument.getObjectNames( E_SCRIPTS, rLibName );
++        sal_Int32 nModCount = aModNames.getLength();
++    	const ::rtl::OUString* pModNames = aModNames.getConstArray();
++
++        BasicEntryDescriptor aDesc( GetEntryDescriptor( pLibSubRootEntry ) );
++        BasicEntryType eCurrentType( aDesc.GetType() );
++
++        for ( sal_Int32 i = 0 ; i < nModCount ; i++ )
++		{
++            String aModName = pModNames[ i ];
++            BasicEntryType eType = OBJ_TYPE_UNKNOWN;
++            switch( lcl_getModuleType( xLib, aModName ) )
++            {
++                case script::ModuleType::Document:
++                    eType = OBJ_TYPE_DOCUMENT_OBJECTS;
++                    break;
++                case script::ModuleType::Form:
++                    eType = OBJ_TYPE_USERFORMS;
++                    break;
++                case script::ModuleType::Normal:
++                    eType = OBJ_TYPE_NORMAL_MODULES;
++                    break;
++                case script::ModuleType::Class:
++                    eType = OBJ_TYPE_CLASS_MODULES;
++                    break;
++            }
++            if( eType != eCurrentType )
++                continue;
++
++			// display a nice friendly name in the ObjectModule tab,
++           	// combining the objectname and module name, e.g. Sheet1 ( Financials )
++            String aEntryName( aModName );
++            if( eType == OBJ_TYPE_DOCUMENT_OBJECTS )
++            {
++	       	    String sObjName;
++            	lcl_getObjectName( xLib, aModName, sObjName );
++		    	if( sObjName.Len() )
++        	   	{
++		        	aEntryName.AppendAscii(" (").Append(sObjName).AppendAscii(")");
++            	}
++            }
++            SvLBoxEntry* pModuleEntry = FindEntry( pLibSubRootEntry, aEntryName, OBJ_TYPE_MODULE );
++            if ( !pModuleEntry )
++                pModuleEntry = AddEntry(
++                    aEntryName,
++                    Image( IDEResId( RID_IMG_MODULE ) ),
++                    Image( IDEResId( RID_IMG_MODULE_HC ) ),
++                    pLibSubRootEntry, false,
++                    std::auto_ptr< BasicEntry >( new BasicEntry( OBJ_TYPE_MODULE ) ) );
++
++			// methods
++			if ( nMode & BROWSEMODE_SUBS )
++			{
++                Sequence< ::rtl::OUString > aNames = BasicIDE::GetMethodNames( rDocument, rLibName, aModName );
++				sal_Int32 nCount = aNames.getLength();
++				const ::rtl::OUString* pNames = aNames.getConstArray();
++
++				for ( sal_Int32 j = 0 ; j < nCount ; j++ )
++				{
++					String aName = pNames[ j ];
++					SvLBoxEntry* pEntry = FindEntry( pModuleEntry, aName, OBJ_TYPE_METHOD );
++                    if ( !pEntry )
++                        pEntry = AddEntry(
++                            aName,
++                            Image( IDEResId( RID_IMG_MACRO ) ),
++                            Image( IDEResId( RID_IMG_MACRO_HC ) ),
++                            pModuleEntry, false,
++                            std::auto_ptr< BasicEntry >( new BasicEntry( OBJ_TYPE_METHOD ) ) );
++    			}
++            }
++	    }
++    }
++    catch ( const container::NoSuchElementException& )
++	{
++        DBG_UNHANDLED_EXCEPTION();
++    }
++}
++
++SvLBoxEntry* BasicTreeListBox::ImpFindEntry( SvLBoxEntry* pParent, const String& rText )
++{
++	ULONG nRootPos = 0;
++	SvLBoxEntry* pEntry = pParent ? FirstChild( pParent ) : GetEntry( nRootPos );
++	while ( pEntry )
++	{
++		if (  GetEntryText( pEntry ) == rText ) 
++			return pEntry;
++
++		pEntry = pParent ? NextSibling( pEntry ) : GetEntry( ++nRootPos );
++	}
++	return 0;
++}
++
+ void BasicTreeListBox::onDocumentCreated( const ScriptDocument& /*_rDocument*/ )
+ {
+     UpdateEntries();
+@@ -480,10 +643,11 @@ long BasicTreeListBox::ExpandingHdl()
+         if ( aDocument.isAlive() )
+         {
+             String aLibName( aDesc.GetLibName() );
++            String aLibSubName( aDesc.GetLibSubName() );
+             String aName( aDesc.GetName() );
+             String aMethodName( aDesc.GetMethodName() );
+ 
+-            if ( aLibName.Len() && !aName.Len() && !aMethodName.Len() )
++            if ( aLibName.Len() && !aLibSubName.Len() && !aName.Len() && !aMethodName.Len() )
+ 		    {
+                 // check password, if library is password protected and not verified
+                 ::rtl::OUString aOULibName( aLibName );
+@@ -636,7 +800,7 @@ void BasicTreeListBox::SetCurrentEntry( 
+         aDesc = BasicEntryDescriptor(
+             ScriptDocument::getApplicationScriptDocument(),
+             LIBRARY_LOCATION_USER, String::CreateFromAscii( "Standard" ), 
+-            String::CreateFromAscii( "." ), OBJ_TYPE_UNKNOWN );
++            String(), String::CreateFromAscii( "." ), OBJ_TYPE_UNKNOWN );
+     }
+     ScriptDocument aDocument( aDesc.GetDocument() );
+     OSL_ENSURE( aDocument.isValid(), "BasicTreeListBox::SetCurrentEntry: invalid document!" );
+@@ -653,14 +817,24 @@ void BasicTreeListBox::SetCurrentEntry( 
+             if ( pLibEntry )
+             {
+                 pCurEntry = pLibEntry;
++                String aLibSubName( aDesc.GetLibSubName() );
++                if( aLibSubName.Len() )
++                {
++                    Expand( pLibEntry );
++                    SvLBoxEntry* pLibSubEntry = ImpFindEntry( pLibEntry, aLibSubName );
++                    if( pLibSubEntry )
++                    {
++                        pCurEntry = pLibSubEntry;
++                    }
++                }
+                 String aName( aDesc.GetName() );
+                 if ( aName.Len() )
+                 {
+-                    Expand( pLibEntry );
++                    Expand( pCurEntry );
+                     BasicEntryType eType = OBJ_TYPE_MODULE;
+                     if ( aDesc.GetType() == OBJ_TYPE_DIALOG )
+                         eType = OBJ_TYPE_DIALOG;
+-                    SvLBoxEntry* pEntry = FindEntry( pLibEntry, aName, eType );
++                    SvLBoxEntry* pEntry = FindEntry( pCurEntry, aName, eType );
+                     if ( pEntry )
+                     {
+                         pCurEntry = pEntry;
+diff --git basctl/source/basicide/bastype2.hxx basctl/source/basicide/bastype2.hxx
+index d93fbfd..81683d5 100644
+--- basctl/source/basicide/bastype2.hxx
++++ basctl/source/basicide/bastype2.hxx
+@@ -42,7 +42,7 @@
+ #include <sbxitem.hxx>
+ #include "basobj.hxx"
+ 
+-enum BasicEntryType { OBJ_TYPE_UNKNOWN, OBJ_TYPE_DOCUMENT, OBJ_TYPE_LIBRARY, OBJ_TYPE_MODULE, OBJ_TYPE_DIALOG, OBJ_TYPE_METHOD };
++enum BasicEntryType { OBJ_TYPE_UNKNOWN, OBJ_TYPE_DOCUMENT, OBJ_TYPE_LIBRARY, OBJ_TYPE_MODULE, OBJ_TYPE_DIALOG, OBJ_TYPE_METHOD, OBJ_TYPE_DOCUMENT_OBJECTS, OBJ_TYPE_USERFORMS, OBJ_TYPE_NORMAL_MODULES, OBJ_TYPE_CLASS_MODULES };
+ 
+ #define BROWSEMODE_MODULES		0x01
+ #define BROWSEMODE_SUBS			0x02
+@@ -101,14 +101,15 @@ class BasicEntryDescriptor
+     ScriptDocument          m_aDocument;
+     LibraryLocation         m_eLocation;
+     String                  m_aLibName;
++    String                  m_aLibSubName;  // for vba entry:  Document Objects, Class Modules, Forms and Normal Modules
+     String                  m_aName;
+     String                  m_aMethodName;
+     BasicEntryType          m_eType;
+ 
+ public:
+                             BasicEntryDescriptor();
+-	                        BasicEntryDescriptor( const ScriptDocument& rDocument, LibraryLocation eLocation, const String& rLibName, const String& rName, BasicEntryType eType );
+-	                        BasicEntryDescriptor( const ScriptDocument& rDocument, LibraryLocation eLocation, const String& rLibName, const String& rName, const String& rMethodName, BasicEntryType eType );
++	                        BasicEntryDescriptor( const ScriptDocument& rDocument, LibraryLocation eLocation, const String& rLibName, const String& rLibSubName, const String& rName, BasicEntryType eType );
++	                        BasicEntryDescriptor( const ScriptDocument& rDocument, LibraryLocation eLocation, const String& rLibName, const String& rLibSubName, const String& rName, const String& rMethodName, BasicEntryType eType );
+     virtual                 ~BasicEntryDescriptor();
+ 
+                             BasicEntryDescriptor( const BasicEntryDescriptor& rDesc );
+@@ -125,6 +126,9 @@ public:
+     const String&           GetLibName() const { return m_aLibName; }
+     void                    SetLibName( const String& aLibName ) { m_aLibName = aLibName; }
+ 
++    const String&           GetLibSubName() const { return m_aLibSubName; }
++    void                    SetLibSubName( const String& aLibSubName ) { m_aLibSubName = aLibSubName; }
++
+     const String&           GetName() const { return m_aName; }
+     void                    SetName( const String& aName ) { m_aName = aName; }
+ 
+@@ -164,6 +168,9 @@ protected:
+ 
+     void                    ImpCreateLibEntries( SvLBoxEntry* pShellRootEntry, const ScriptDocument& rDocument, LibraryLocation eLocation );
+ 	void 					ImpCreateLibSubEntries( SvLBoxEntry* pLibRootEntry, const ScriptDocument& rDocument, const String& rLibName );
++	void 					ImpCreateLibSubEntriesInVBAMode( SvLBoxEntry* pLibRootEntry, const ScriptDocument& rDocument, const String& rLibName );
++	void 					ImpCreateLibSubSubEntriesInVBAMode( SvLBoxEntry* pLibSubRootEntry, const ScriptDocument& rDocument, const String& rLibName );
++    SvLBoxEntry*            ImpFindEntry( SvLBoxEntry* pParent, const String& rText );
+ 
+     // DocumentEventListener
+     virtual void onDocumentCreated( const ScriptDocument& _rDocument );
+diff --git basctl/source/basicide/bastype3.cxx basctl/source/basicide/bastype3.cxx
+index c282f5d..accbce2 100644
+--- basctl/source/basicide/bastype3.cxx
++++ basctl/source/basicide/bastype3.cxx
+@@ -134,6 +134,14 @@ void __EXPORT BasicTreeListBox::Requesti
+ 		    }
+         }
+     }
++    else if ( eType == OBJ_TYPE_DOCUMENT_OBJECTS 
++            || eType == OBJ_TYPE_USERFORMS
++            || eType == OBJ_TYPE_NORMAL_MODULES
++            || eType == OBJ_TYPE_CLASS_MODULES )
++    {
++        String aLibName( aDesc.GetLibName() );
++        ImpCreateLibSubSubEntriesInVBAMode( pEntry, aDocument, aLibName );
++    }
+ 	else {
+ 		DBG_ERROR( "BasicTreeListBox::RequestingChilds: Unknown Type!" );
+     }
+@@ -204,6 +212,7 @@ SbxVariable* BasicTreeListBox::FindVaria
+     }
+ 
+ 	SbxVariable* pVar = 0;
++    bool bDocumentObjects = false;
+ 	if ( aEntries.Count() )
+ 	{
+ 		for ( USHORT n = 0; n < aEntries.Count(); n++ )
+@@ -226,6 +235,12 @@ SbxVariable* BasicTreeListBox::FindVaria
+ 				case OBJ_TYPE_MODULE:
+ 				{
+ 					DBG_ASSERT( pVar && pVar->IsA( TYPE(StarBASIC) ), "FindVariable: Ungueltiges Basic" );
++                    // extract the module name from the string like "Sheet1 (Example1)"
++                    if( bDocumentObjects )
++                    {
++                        sal_uInt16 nIndex = 0;
++                        aName = aName.GetToken( 0, ' ', nIndex );
++                    }
+ 					pVar = ((StarBASIC*)pVar)->FindModule( aName );
+ 				}
+ 				break;
+@@ -240,6 +255,15 @@ SbxVariable* BasicTreeListBox::FindVaria
+ 					// sbx dialogs removed
+ 				}
+ 				break;
++                case OBJ_TYPE_DOCUMENT_OBJECTS:
++                    bDocumentObjects = true;
++                case OBJ_TYPE_USERFORMS:
++                case OBJ_TYPE_NORMAL_MODULES:
++                case OBJ_TYPE_CLASS_MODULES:
++                {
++                    // skip, to find the child entry.
++                    continue;
++                }
+                 default:
+                 {
+                     DBG_ERROR( "FindVariable: Unbekannter Typ!" );
+@@ -260,12 +284,13 @@ BasicEntryDescriptor BasicTreeListBox::G
+     ScriptDocument aDocument( ScriptDocument::getApplicationScriptDocument() );
+     LibraryLocation eLocation = LIBRARY_LOCATION_UNKNOWN;
+ 	String aLibName;
++	String aLibSubName;
+ 	String aName;
+ 	String aMethodName;
+     BasicEntryType eType = OBJ_TYPE_UNKNOWN;
+ 
+ 	if ( !pEntry )
+-        return BasicEntryDescriptor( aDocument, eLocation, aLibName, aName, aMethodName, eType );
++        return BasicEntryDescriptor( aDocument, eLocation, aLibName, aLibSubName, aName, aMethodName, eType );
+ 
+ 	EntryArray aEntries;
+ 
+@@ -332,6 +357,15 @@ BasicEntryDescriptor BasicTreeListBox::G
+ 					eType = pBE->GetType();
+ 				}
+ 				break;
++                case OBJ_TYPE_DOCUMENT_OBJECTS:
++                case OBJ_TYPE_USERFORMS:
++                case OBJ_TYPE_NORMAL_MODULES:
++                case OBJ_TYPE_CLASS_MODULES:
++				{
++					aLibSubName = GetEntryText( pLE );
++					eType = pBE->GetType();
++				}
++				break;
+ 				default:
+                 {
+                     DBG_ERROR( "GetEntryDescriptor: Unbekannter Typ!" );
+@@ -345,7 +379,7 @@ BasicEntryDescriptor BasicTreeListBox::G
+ 		}
+ 	}
+ 
+-    return BasicEntryDescriptor( aDocument, eLocation, aLibName, aName, aMethodName, eType );
++    return BasicEntryDescriptor( aDocument, eLocation, aLibName, aLibSubName, aName, aMethodName, eType );
+ }
+ 
+ USHORT BasicTreeListBox::ConvertType( BasicEntryType eType )
+@@ -427,6 +461,14 @@ bool BasicTreeListBox::IsValidEntry( SvL
+             bIsValid = BasicIDE::HasMethod( aDocument, aLibName, aName, aMethodName );
+         }
+         break;
++        case OBJ_TYPE_DOCUMENT_OBJECTS:
++        case OBJ_TYPE_USERFORMS:
++        case OBJ_TYPE_NORMAL_MODULES:
++        case OBJ_TYPE_CLASS_MODULES:
++        {
++            bIsValid = true;
++        }
++        break;
+ 		default: ;
+     }
+ 
+diff --git basctl/source/basicide/macrodlg.cxx basctl/source/basicide/macrodlg.cxx
+index 229d999..a6013cf 100644
+--- basctl/source/basicide/macrodlg.cxx
++++ basctl/source/basicide/macrodlg.cxx
+@@ -385,7 +385,15 @@ SbMethod* MacroChooser::CreateMacro()
+         SbModule* pModule = 0;
+         String aModName( aDesc.GetName() );
+         if ( aModName.Len() )
++        {
++            // extract the module name from the string like "Sheet1 (Example1)"
++            if( aDesc.GetLibSubName().Equals( String( IDEResId( RID_STR_DOCUMENT_OBJECTS ) ) ) )
++            {
++                sal_uInt16 nIndex = 0;
++                aModName = aModName.GetToken( 0, ' ', nIndex );
++            }
+ 	        pModule = pBasic->FindModule( aModName );
++        }    
+         else if ( pBasic->GetModules()->Count() )
+ 	        pModule = (SbModule*)pBasic->GetModules()->Get( 0 );
+ 
+@@ -713,6 +721,12 @@ IMPL_LINK( MacroChooser, ButtonHdl, Butt
+         BasicManager* pBasMgr = aDocument.getBasicManager();
+         String aLib( aDesc.GetLibName() );
+         String aMod( aDesc.GetName() );
++        // extract the module name from the string like "Sheet1 (Example1)"
++        if( aDesc.GetLibSubName().Equals( String( IDEResId( RID_STR_DOCUMENT_OBJECTS ) ) ) )
++        {
++            sal_uInt16 nIndex = 0;
++            aMod = aMod.GetToken( 0, ' ', nIndex );
++        }
+         String aSub( aDesc.GetMethodName() );
+ 		SfxMacroInfoItem aInfoItem( SID_BASICIDE_ARG_MACROINFO, pBasMgr, aLib, aMod, aSub, String() );
+ 		if ( pButton == &aEditButton )
+diff --git basctl/source/basicide/moduldlg.cxx basctl/source/basicide/moduldlg.cxx
+index cd2c032..23b890c 100644
+--- basctl/source/basicide/moduldlg.cxx
++++ basctl/source/basicide/moduldlg.cxx
+@@ -87,7 +87,7 @@ BOOL __EXPORT ExtBasicTreeListBox::Editi
+     if ( pEntry )
+     {
+         USHORT nDepth = GetModel()->GetDepth( pEntry );
+-        if ( nDepth == 2 )
++        if ( nDepth >= 2 )
+         {
+             BasicEntryDescriptor aDesc( GetEntryDescriptor( pEntry ) );
+             ScriptDocument aDocument( aDesc.GetDocument() );
+@@ -165,7 +165,7 @@ DragDropMode __EXPORT ExtBasicTreeListBo
+     if ( pEntry )
+     {
+         USHORT nDepth = GetModel()->GetDepth( pEntry );
+-        if ( nDepth == 2 )
++        if ( nDepth >= 2 )
+         {
+             nMode_ = SV_DRAGDROP_CTRL_COPY;
+             BasicEntryDescriptor aDesc( GetEntryDescriptor( pEntry ) );
+@@ -213,7 +213,7 @@ BOOL __EXPORT ExtBasicTreeListBox::Notif
+ 
+     // don't drop on a library, which is not loaded, readonly or password protected
+     // or which already has a module/dialog with this name
+-    if ( bValid && ( nDepth == 1 || nDepth == 2 ) )
++    if ( bValid && ( nDepth > 0 ) )
+     {
+ 		// get source module/dialog name
+         BasicEntryDescriptor aSourceDesc( GetEntryDescriptor( pSelected ) );
+@@ -351,7 +351,7 @@ BOOL __EXPORT ExtBasicTreeListBox::Notif
+ 		rpNewParent = pTarget;
+ 		rNewChildPos = 0;
+ 	}
+-	else if ( nDepth == 2 )
++	else if ( nDepth >= 2 )
+ 	{
+ 		// Target = Modul/Dialog => Modul/Dialog unter das uebergeordnete Basic haengen...
+ 		rpNewParent = GetParent( pTarget );
+@@ -626,20 +626,27 @@ void ObjectPage::CheckButtons()
+ {
+     // enable/disable edit button
+ 	SvLBoxEntry* pCurEntry = aBasicBox.GetCurEntry();
++    BasicEntryDescriptor aDesc( aBasicBox.GetEntryDescriptor( pCurEntry ) );
++    ScriptDocument aDocument( aDesc.GetDocument() );
++    ::rtl::OUString aOULibName( aDesc.GetLibName() );
++    String aLibSubName( aDesc.GetLibSubName() );
++    BasicManager* pBasMgr = aDocument.getBasicManager();
++    StarBASIC* pBasic = pBasMgr ? pBasMgr->GetLib( aOULibName ) : 0;
++    sal_Bool bVBAEnabled = pBasic ? pBasic->isVBAEnabled(): sal_False;
++    USHORT nMode = aBasicBox.GetMode();
++
+ 	USHORT nDepth = pCurEntry ? aBasicBox.GetModel()->GetDepth( pCurEntry ) : 0;
+-	if ( nDepth == 2 )
++	if ( ( !bVBAEnabled && ( nDepth == 2 ) ) 
++        || ( bVBAEnabled && ( nMode & BROWSEMODE_MODULES ) && ( nDepth == 3 ) ) )
+ 		aEditButton.Enable();
+ 	else
+ 		aEditButton.Disable();
+ 
+     // enable/disable new module/dialog buttons
+-    BasicEntryDescriptor aDesc( aBasicBox.GetEntryDescriptor( pCurEntry ) );
+     LibraryLocation eLocation( aDesc.GetLocation() );
+     BOOL bReadOnly = FALSE;
+-    if ( nDepth == 1 || nDepth == 2 )
++    if ( nDepth > 0 )
+     {
+-        ScriptDocument aDocument( aDesc.GetDocument() );
+-        ::rtl::OUString aOULibName( aDesc.GetLibName() );
+         Reference< script::XLibraryContainer2 > xModLibContainer( aDocument.getLibraryContainer( E_SCRIPTS ), UNO_QUERY );
+         Reference< script::XLibraryContainer2 > xDlgLibContainer( aDocument.getLibraryContainer( E_DIALOGS ), UNO_QUERY );
+         if ( ( xModLibContainer.is() && xModLibContainer->hasByName( aOULibName ) && xModLibContainer->isLibraryReadOnly( aOULibName ) ) ||
+@@ -660,7 +667,8 @@ void ObjectPage::CheckButtons()
+     }
+ 
+     // enable/disable delete button
+-	if ( nDepth == 2 && !bReadOnly && eLocation != LIBRARY_LOCATION_SHARE )
++	if ( ( ( !bVBAEnabled && nDepth == 2 ) || ( bVBAEnabled && ( nDepth == 3 ) && !aLibSubName.Equals( String( IDEResId( RID_STR_DOCUMENT_OBJECTS ) ) ) ) )
++        && !bReadOnly && eLocation != LIBRARY_LOCATION_SHARE )
+ 		aDelButton.Enable();
+ 	else
+ 		aDelButton.Disable();
+@@ -688,13 +696,20 @@ IMPL_LINK( ObjectPage, ButtonHdl, Button
+         SfxDispatcher* pDispatcher = pViewFrame ? pViewFrame->GetDispatcher() : NULL;
+         SvLBoxEntry* pCurEntry = aBasicBox.GetCurEntry();
+ 		DBG_ASSERT( pCurEntry, "Entry?!" );
+-		if ( aBasicBox.GetModel()->GetDepth( pCurEntry ) == 2 )
++		if ( aBasicBox.GetModel()->GetDepth( pCurEntry ) >= 2 )
+ 		{
+             BasicEntryDescriptor aDesc( aBasicBox.GetEntryDescriptor( pCurEntry ) );
+ 			if ( pDispatcher )
+ 			{
++                String aModName( aDesc.GetName() );
++                // extract the module name from the string like "Sheet1 (Example1)"
++                if( aDesc.GetLibSubName().Equals( String( IDEResId( RID_STR_DOCUMENT_OBJECTS ) ) ) )
++                {
++                    sal_uInt16 nIndex = 0;
++                    aModName = aModName.GetToken( 0, ' ', nIndex );
++                }
+                 SbxItem aSbxItem( SID_BASICIDE_ARG_SBX, aDesc.GetDocument(), aDesc.GetLibName(), 
+-                                  aDesc.GetName(), aBasicBox.ConvertType( aDesc.GetType() ) );
++                                  aModName, aBasicBox.ConvertType( aDesc.GetType() ) );
+ 				pDispatcher->Execute( SID_BASICIDE_SHOWSBX, SFX_CALLMODE_SYNCHRON, &aSbxItem, 0L );
+ 			}
+ 		}
+@@ -976,14 +991,14 @@ SbModule* createModImpl( Window* pWin, c
+ 		try
+ 		{
+             ::rtl::OUString sModuleCode;
++            // the module has existed
++            if( rDocument.hasModule( aLibName, aModName ) )
++                return NULL;
+             rDocument.createModule( aLibName, aModName, bMain, sModuleCode );
+             BasicManager* pBasMgr = rDocument.getBasicManager();
+-            if ( pBasMgr )
+-            {
+-                StarBASIC* pBasic = pBasMgr->GetLib( aLibName );
+-                if ( pBasic )
+-                    pModule = pBasic->FindModule( aModName );
+-            }
++            StarBASIC* pBasic = pBasMgr? pBasMgr->GetLib( aLibName ) : 0;
++            if ( pBasic )
++                pModule = pBasic->FindModule( aModName );
+ 			SbxItem aSbxItem( SID_BASICIDE_ARG_SBX, rDocument, aLibName, aModName, BASICIDE_TYPE_MODULE );					
+ 			BasicIDEShell* pIDEShell = IDE_DLL()->GetShell();
+ 			SfxViewFrame* pViewFrame = pIDEShell ? pIDEShell->GetViewFrame() : NULL;
+@@ -1005,14 +1020,27 @@ SbModule* createModImpl( Window* pWin, c
+                 {
+                     if ( !rBasicBox.IsExpanded( pLibEntry ) )
+                         rBasicBox.Expand( pLibEntry );
+-                    SvLBoxEntry* pEntry = rBasicBox.FindEntry( pLibEntry, aModName, OBJ_TYPE_MODULE );
++                    SvLBoxEntry* pSubRootEntry = pLibEntry;
++                    if( pBasic && pBasic->isVBAEnabled() )
++                    {
++                        // add the new module in the "Modules" entry
++                        SvLBoxEntry* pLibSubEntry = rBasicBox.FindEntry( pLibEntry, String( IDEResId( RID_STR_NORMAL_MODULES ) ) , OBJ_TYPE_NORMAL_MODULES );
++                        if( pLibSubEntry )
++                        {
++                            if( !rBasicBox.IsExpanded( pLibSubEntry ) )
++                                rBasicBox.Expand( pLibSubEntry );
++                            pSubRootEntry = pLibSubEntry;    
++                        }
++                    }
++                    
++                    SvLBoxEntry* pEntry = rBasicBox.FindEntry( pSubRootEntry, aModName, OBJ_TYPE_MODULE );
+                     if ( !pEntry )
+                     {
+                         pEntry = rBasicBox.AddEntry(
+                             aModName,
+                             Image( IDEResId( RID_IMG_MODULE ) ),
+                             Image( IDEResId( RID_IMG_MODULE_HC ) ),
+-                            pLibEntry, false,
++                            pSubRootEntry, false,
+                             std::auto_ptr< BasicEntry >( new BasicEntry( OBJ_TYPE_MODULE ) ) );
+                         DBG_ASSERT( pEntry, "InsertEntry fehlgeschlagen!" );
+                     }

Added: trunk/patches/vba/native-export/vba-compatible-mode-uno.diff
==============================================================================
--- (empty file)
+++ trunk/patches/vba/native-export/vba-compatible-mode-uno.diff	Wed Oct 29 15:27:45 2008
@@ -0,0 +1,127 @@
+diff --git xmlscript/source/xmldlg_imexp/imp_share.hxx xmlscript/source/xmldlg_imexp/imp_share.hxx
+index e5263ad..814bb21 100644
+--- xmlscript/source/xmldlg_imexp/imp_share.hxx
++++ xmlscript/source/xmldlg_imexp/imp_share.hxx
+@@ -45,6 +45,7 @@
+ #include <com/sun/star/awt/FontEmphasisMark.hpp>
+ #include <com/sun/star/awt/FontRelief.hpp>
+ #include <com/sun/star/xml/input/XRoot.hpp>
++#include <com/sun/star/script/XBasicLibraryInfo.hpp>
+ #include <vector>
+ 
+ 
+@@ -177,6 +178,8 @@ public:
+         SAL_THROW( () );
+     
+     inline css::uno::Reference< css::frame::XModel > getDocOwner() { return _xDoc; }
++    css::uno::Reference< css::script::XBasicLibraryInfo > getScriptLibraryInfo();
++
+     // XRoot
+     virtual void SAL_CALL startDocument(
+         css::uno::Reference< css::xml::input::XNamespaceMapping >
+diff --git xmlscript/source/xmldlg_imexp/xmldlg_impmodels.cxx xmlscript/source/xmldlg_imexp/xmldlg_impmodels.cxx
+index 310b3a6..9885fc4 100644
+--- xmlscript/source/xmldlg_imexp/xmldlg_impmodels.cxx
++++ xmlscript/source/xmldlg_imexp/xmldlg_impmodels.cxx
+@@ -41,6 +41,7 @@
+ #include <com/sun/star/beans/XPropertyState.hpp>
+ #include <com/sun/star/document/XStorageBasedDocument.hpp>
+ #include <com/sun/star/document/XGraphicObjectResolver.hpp>
++#include <com/sun/star/script/XBasicLibraryInfo.hpp>
+ 
+ #include <comphelper/componentcontext.hxx>
+ #include <comphelper/processfactory.hxx>
+@@ -145,6 +146,16 @@ void importBindableAndListRangeBits( Dia
+        }
+    }
+ }
++
++sal_Bool isVBACompatModeOn( DialogImport* _pImport )
++{
++	sal_Bool bVBAMode = sal_False;
++	Reference< script::XBasicLibraryInfo > xVBAInfo( _pImport->getScriptLibraryInfo(), UNO_QUERY );
++	if ( xVBAInfo.is() )
++		bVBAMode = xVBAInfo->getVBACompatMode();
++	return bVBAMode;
++}
++
+ // progessmeter
+ //__________________________________________________________________________________________________
+ Reference< xml::input::XElement > ProgressBarElement::startChildElement(
+@@ -1475,7 +1486,7 @@ void TitledBoxElement::endElement()
+ 		{
+ 			sLinkedCell = xAttributes->getValueByUidName( _pImport->XMLNS_DIALOGS_UID, OUSTR( "linked-cell" ) );
+ 			// we should probably limit this to vba mode also ( leave for now )
+-			if ( _pImport->getDocOwner().is() )
++			if ( isVBACompatModeOn( _pImport ) )
+ 				sService = OUSTR("com.sun.star.form.component.RadioButton");
+ 		}
+ 		catch( Exception& /*e*/ )
+@@ -1620,7 +1631,7 @@ void RadioGroupElement::endElement()
+ 		{
+ 			sLinkedCell = xAttributes->getValueByUidName( _pImport->XMLNS_DIALOGS_UID, OUSTR( "linked-cell" ) );
+ 			// we should probably limit this to vba mode also ( leave for now )
+-			if ( _pImport->getDocOwner().is() )
++			if ( isVBACompatModeOn( _pImport ) )
+ 				sService = OUSTR("com.sun.star.form.component.RadioButton");
+ 		}
+ 		catch( Exception& /*e*/ )
+@@ -1807,7 +1818,7 @@ void MenuListElement::endElement()
+         OUString sListBoxService( OUSTR("com.sun.star.awt.UnoControlListBoxModel") );
+ 
+         // we should probably limit this to vba mode also ( leave for now )
+-        if ( _pImport->getDocOwner().is() )
++        if ( isVBACompatModeOn( _pImport ) )
+             sListBoxService = OUSTR("com.sun.star.form.component.ListBox");
+ 
+         try
+diff --git xmlscript/source/xmldlg_imexp/xmldlg_import.cxx xmlscript/source/xmldlg_imexp/xmldlg_import.cxx
+index 99064cc..e4f6647 100644
+--- xmlscript/source/xmldlg_imexp/xmldlg_import.cxx
++++ xmlscript/source/xmldlg_imexp/xmldlg_import.cxx
+@@ -59,6 +59,9 @@
+ #include <com/sun/star/script/ScriptEventDescriptor.hpp>
+ 
+ #include <com/sun/star/view/SelectionType.hpp>
++#include <com/sun/star/document/XStorageBasedDocument.hpp>
++#include <com/sun/star/script/XBasicLibraryInfo.hpp>
++
+ 
+ using namespace ::com::sun::star;
+ using namespace ::com::sun::star::uno;
+@@ -1875,6 +1878,35 @@ Reference< xml::input::XElement > Dialog
+     return 0;
+ }
+ 
++//__________________________________________________________________________________________________
++Reference< script::XBasicLibraryInfo > DialogImport::getScriptLibraryInfo()
++{
++    // #FIXME this is a hack, we should know about the library that 
++    // 'owns' the dialog ( in order to determine it's vba mode )
++    Reference< script::XBasicLibraryInfo >  xLib;
++    if ( _xDoc.is() )
++    {
++        Reference< beans::XPropertySet > xProps( _xDoc, UNO_QUERY );
++        if ( xProps.is() )
++        {
++            try
++            {
++                Reference< container::XNameAccess >  xLibContainer;
++                xProps->getPropertyValue( OUSTR("BasicLibraries") ) >>= xLibContainer;
++                if ( xLibContainer.is() )
++                {
++                    xLibContainer->getByName( OUSTR("Standard") ) >>= xLib;
++                }
++            
++            }
++            catch( Exception& )
++            {
++            }
++        }
++   }
++   return xLib;
++}
++
+ //##################################################################################################
+ 
+ //==================================================================================================

Added: trunk/patches/vba/native-export/vba-userform-geometry-tweak.diff
==============================================================================
--- (empty file)
+++ trunk/patches/vba/native-export/vba-userform-geometry-tweak.diff	Wed Oct 29 15:27:45 2008
@@ -0,0 +1,415 @@
+diff --git basctl/source/basicide/baside3.cxx basctl/source/basicide/baside3.cxx
+index e89c22f..a0e9f1b 100644
+--- basctl/source/basicide/baside3.cxx
++++ basctl/source/basicide/baside3.cxx
+@@ -82,6 +82,7 @@
+ #include <com/sun/star/resource/XStringResourceResolver.hpp>
+ #include <com/sun/star/resource/StringResourceWithLocation.hpp>
+ #include <com/sun/star/task/XInteractionHandler.hpp>
++#include <com/sun/star/script/XBasicLibraryInfo.hpp>
+ 
+ using namespace comphelper;
+ using namespace	::com::sun::star;
+@@ -114,6 +115,23 @@ DialogWindow::DialogWindow( Window* pPar
+ 
+ 	pEditor = new DlgEditor( rDocument.getDocument() );
+ 	pEditor->SetWindow( this );
++	// set vba mode on DialogModel ( allows it to work in 100thmm instead of MAP_APPFONT )
++	if ( rDocument.getDocument().is() )
++	{
++		uno::Reference< script::XBasicLibraryInfo > xLibInfo( rDocument.getLibraryContainer( E_SCRIPTS ), uno::UNO_QUERY );
++		if ( xLibInfo.is()  && xLibInfo->getVBACompatMode() )
++		{
++			try
++			{
++				Reference< beans::XPropertySet > xDlgProps( xDialogModel, UNO_QUERY_THROW );
++				xDlgProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("VBAForm") ), makeAny( sal_True ) );
++			}
++			catch( Exception& )
++			{
++			}
++
++		}
++	}
+ 	pEditor->SetDialog( xDialogModel );
+ 
+ 	// Undo einrichten
+diff --git basctl/source/dlged/dlgedobj.cxx basctl/source/dlged/dlgedobj.cxx
+index bed7bc3..ae7df5c 100644
+--- basctl/source/dlged/dlgedobj.cxx
++++ basctl/source/dlged/dlgedobj.cxx
+@@ -56,6 +56,7 @@
+ #include <com/sun/star/beans/XPropertySet.hpp>
+ #include <com/sun/star/beans/PropertyAttribute.hpp>
+ #include <com/sun/star/script/XScriptEventsSupplier.hpp>
++#include <com/sun/star/script/XBasicLibraryInfo.hpp>
+ #include <com/sun/star/container/XContainer.hpp>
+ #include <com/sun/star/lang/XServiceInfo.hpp>
+ #include <comphelper/processfactory.hxx>
+@@ -77,6 +78,22 @@ TYPEINIT1(DlgEdObj, SdrUnoObj);
+ DBG_NAME(DlgEdObj);
+ 
+ //----------------------------------------------------------------------------
++MapMode lcl_getMapModeForForm( DlgEdForm* pForm )
++{
++	MapMode aMode( MAP_APPFONT ); //Default
++	try
++	{
++		uno::Reference< beans::XPropertySet > xProps( pForm ? pForm->GetUnoControlModel() : NULL, uno::UNO_QUERY_THROW );
++		sal_Bool bVBAForm = sal_False;
++		xProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("VBAForm") ) ) >>= bVBAForm;	
++		if ( bVBAForm )
++			aMode = MapMode( MAP_100TH_MM );
++	}
++	catch ( Exception& )
++	{
++	}
++	return aMode;
++}
+ 
+ DlgEdObj::DlgEdObj()
+ 		  :SdrUnoObj(String(), sal_False)
+@@ -207,8 +224,9 @@ bool DlgEdObj::TransformSdrToControlCoor
+ 	}
+     
+     // convert pixel to logic units
+-    aPos = pDevice->PixelToLogic( aPos, MapMode( MAP_APPFONT ) );
+-    aSize = pDevice->PixelToLogic( aSize, MapMode( MAP_APPFONT ) );
++    MapMode aConvMode = lcl_getMapModeForForm( pForm );
++    aPos = pDevice->PixelToLogic( aPos, aConvMode );
++    aSize = pDevice->PixelToLogic( aSize, aConvMode );
+ 
+     // set out parameters
+     nXOut = aPos.Width();
+@@ -255,10 +273,10 @@ bool DlgEdObj::TransformSdrToFormCoordin
+ 		aSize.Width() -= aDeviceInfo.LeftInset + aDeviceInfo.RightInset;
+ 		aSize.Height() -= aDeviceInfo.TopInset + aDeviceInfo.BottomInset;
+ 	}
+-
++    MapMode aConvMode = lcl_getMapModeForForm( pForm );
+     // convert pixel to logic units
+-    aPos = pDevice->PixelToLogic( aPos, MapMode( MAP_APPFONT ) );
+-    aSize = pDevice->PixelToLogic( aSize, MapMode( MAP_APPFONT ) );
++    aPos = pDevice->PixelToLogic( aPos, aConvMode );
++    aSize = pDevice->PixelToLogic( aSize, aConvMode );
+ 
+     // set out parameters
+     nXOut = aPos.Width();
+@@ -300,9 +318,10 @@ bool DlgEdObj::TransformControlToSdrCoor
+     DBG_ASSERT( pDevice, "DlgEdObj::TransformControlToSdrCoordinates: missing default device!" );
+     if ( !pDevice )
+         return false;
+-    aPos = pDevice->LogicToPixel( aPos, MapMode( MAP_APPFONT ) );
+-    aSize = pDevice->LogicToPixel( aSize, MapMode( MAP_APPFONT ) );
+-    aFormPos = pDevice->LogicToPixel( aFormPos, MapMode( MAP_APPFONT ) );
++    MapMode aConvMode = lcl_getMapModeForForm( pForm );
++    aPos = pDevice->LogicToPixel( aPos, aConvMode );
++    aSize = pDevice->LogicToPixel( aSize, aConvMode );
++    aFormPos = pDevice->LogicToPixel( aFormPos, aConvMode );
+ 
+     // add form position
+     aPos.Width() += aFormPos.Width();
+@@ -346,14 +365,16 @@ bool DlgEdObj::TransformFormToSdrCoordin
+     DBG_ASSERT( pDevice, "DlgEdObj::TransformFormToSdrCoordinates: missing default device!" );
+     if ( !pDevice )
+         return false;
+-    aPos = pDevice->LogicToPixel( aPos, MapMode( MAP_APPFONT ) );
+-    aSize = pDevice->LogicToPixel( aSize, MapMode( MAP_APPFONT ) );
+ 
+     // take window borders into account
+     DlgEdForm* pForm = NULL;
+     if ( !lcl_getDlgEdForm( this, pForm ) )
+         return false;
+ 
++    MapMode aConvMode = lcl_getMapModeForForm( pForm );
++    aPos = pDevice->LogicToPixel( aPos, aConvMode );
++    aSize = pDevice->LogicToPixel( aSize, aConvMode );
++
+     // take window borders into account
+     Reference< beans::XPropertySet > xPSetForm( pForm->GetUnoControlModel(), UNO_QUERY );
+     DBG_ASSERT( xPSetForm.is(), "DlgEdObj::TransformFormToSdrCoordinates: no form property set!" );
+diff --git svx/inc/svxmsbas.hxx svx/inc/svxmsbas.hxx
+index f99247b..5e87fe6 100644
+--- svx/inc/svxmsbas.hxx
++++ svx/inc/svxmsbas.hxx
+@@ -99,7 +99,7 @@ private:
+ 						  const String &rSubStorageName,
+ 						  BOOL bAsComment, BOOL bStripped );
+ 	SVX_DLLPRIVATE bool ImportForms_Impl(const String& rStorageName, 
+-		const String &rSubStorageName);
++		const String &rSubStorageName, BOOL bVBAMode );
+ 	SVX_DLLPRIVATE BOOL CopyStorage_Impl( const String& rStorageName,
+ 						   const String &rSubStorageName);
+ };
+diff --git svx/source/msfilter/msocximex.cxx svx/source/msfilter/msocximex.cxx
+index 1075424..46986eb 100644
+--- svx/source/msfilter/msocximex.cxx
++++ svx/source/msfilter/msocximex.cxx
+@@ -1075,6 +1075,9 @@ sal_Bool OCX_Control::Import(
+ sal_Bool OCX_Control::Import(uno::Reference<container::XNameContainer> &rDialog
+     )
+ {
++    uno::Reference<beans::XPropertySet > xDlgProps( rDialog, uno::UNO_QUERY);
++
++    
+     uno::Reference<lang::XMultiServiceFactory>
+         xFactory(rDialog, uno::UNO_QUERY);
+ 
+@@ -1087,11 +1090,15 @@ sal_Bool OCX_Control::Import(uno::Refere
+ 	if (!xModel.is())
+ 		return sal_False;
+ 
++    sal_Bool bVBA = sal_False;
+     /*  #147900# sometimes insertion of a control fails due to existing name,
+         do not break entire form import then... */
+     try
+     {
+         rDialog->insertByName(sName, uno::makeAny(xModel));
++        if ( xDlgProps.is() )
++            xDlgProps->getPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("VBAForm") ) ) >>= bVBA;
++
+     }
+     catch( uno::Exception& )
+     {
+@@ -1107,16 +1114,32 @@ sal_Bool OCX_Control::Import(uno::Refere
+ 
+     if (!Import(xPropSet))
+         return sal_False;
+-
++    
+     uno::Any aTmp;
+-    aTmp <<= sal_Int32((mnLeft * 2) / 100);
+-    xPropSet->setPropertyValue(WW8_ASCII2STR("PositionX"), aTmp);
+-    aTmp <<= sal_Int32((mnTop * 2) / 100);
+-    xPropSet->setPropertyValue(WW8_ASCII2STR("PositionY"), aTmp);
+-    aTmp <<= sal_Int32((nWidth * 2) / 100);
+-    xPropSet->setPropertyValue(WW8_ASCII2STR("Width"), aTmp);
+-    aTmp <<= sal_Int32((nHeight * 2) / 100);
+-    xPropSet->setPropertyValue(WW8_ASCII2STR("Height"), aTmp);
++    sal_Int32 nFactor = 3528; 
++
++    if ( !bVBA  )
++    {
++        aTmp <<= sal_Int32((mnLeft * 2) / 100);
++        xPropSet->setPropertyValue(WW8_ASCII2STR("PositionX"), aTmp);
++        aTmp <<= sal_Int32((mnTop * 2) / 100);
++        xPropSet->setPropertyValue(WW8_ASCII2STR("PositionY"), aTmp);
++        aTmp <<= sal_Int32((nWidth * 2) / 100);
++        xPropSet->setPropertyValue(WW8_ASCII2STR("Width"), aTmp);
++        aTmp <<= sal_Int32((nHeight * 2) / 100);
++        xPropSet->setPropertyValue(WW8_ASCII2STR("Height"), aTmp);
++    }
++    else
++    {
++        aTmp <<= sal_Int32(mnLeft); // 100thmm
++        xPropSet->setPropertyValue(WW8_ASCII2STR("PositionX"), aTmp);
++        aTmp <<= sal_Int32(mnTop); //100th mm
++        xPropSet->setPropertyValue(WW8_ASCII2STR("PositionY"), aTmp);
++        aTmp <<= sal_Int32(nWidth); // 100thmm
++        xPropSet->setPropertyValue(WW8_ASCII2STR("Width"), aTmp);
++        aTmp <<= sal_Int32(nHeight); //100th mm
++        xPropSet->setPropertyValue(WW8_ASCII2STR("Height"), aTmp);
++    }
+     if ( msToolTip.Len() > 0 )
+     {
+ 	uno::Any aTmp(&msToolTip,getCppuType((OUString *)0));
+@@ -4321,6 +4344,8 @@ sal_Bool OCX_UserForm::Import(
+ {
+     uno::Reference<beans::XPropertySet>
+         xDialogPropSet(mxParent, uno::UNO_QUERY);
++    if ( !xDialogPropSet.is() )
++        return sal_False;
+     uno::Any aTmp(&sName,getCppuType((OUString *)0));
+     xDialogPropSet->setPropertyValue(
+         OUString(RTL_CONSTASCII_USTRINGPARAM("Name")), aTmp);
+@@ -4328,11 +4353,32 @@ sal_Bool OCX_UserForm::Import(
+         OUString(RTL_CONSTASCII_USTRINGPARAM("Title")), aTmp);
+     aTmp <<= ImportColor(mnBackColor);
+ 	xDialogPropSet->setPropertyValue( WW8_ASCII2STR("BackgroundColor"), aTmp);
++    sal_Bool bVBA = sal_False;
++    // Ok we are importing xls but maybe we aren't in VBA mode
++    // if we are not in VBA mode then we should import sizes etc. ( as before )
++    try
++    {
++        xDialogPropSet->getPropertyValue( OUString(RTL_CONSTASCII_USTRINGPARAM("VBAForm") ) ) >>= bVBA;
++    }
++    catch( uno::Exception& e )
++    {
++    }
++    sal_Int32 nFactor( 3528 );
++    if ( !bVBA )
++    {
++        aTmp <<= sal_Int32((nWidth * 2) / 100); 
++        xDialogPropSet->setPropertyValue(WW8_ASCII2STR("Width"), aTmp);
++        aTmp <<= sal_Int32((nHeight * 2) / 100); 
++        xDialogPropSet->setPropertyValue(WW8_ASCII2STR("Height"), aTmp);
++    }
++    else
++    {
++        aTmp <<= sal_Int32( nWidth + 160 ); // 100thmm
++        xDialogPropSet->setPropertyValue(WW8_ASCII2STR("Width"), aTmp);
++        aTmp <<= sal_Int32(nHeight + 662 - 714); //100th mm
++        xDialogPropSet->setPropertyValue(WW8_ASCII2STR("Height"), aTmp);
++    }
+ 
+-    aTmp <<= sal_Int32((nWidth * 2) / 100);
+-    xDialogPropSet->setPropertyValue(WW8_ASCII2STR("Width"), aTmp);
+-    aTmp <<= sal_Int32((nHeight * 2) / 100);
+-    xDialogPropSet->setPropertyValue(WW8_ASCII2STR("Height"), aTmp);
+ 
+     uno::Reference<beans::XPropertySet> xPropSet( mxParent, uno::UNO_QUERY );
+     OCX_ContainerControl::Import( xPropSet );
+diff --git svx/source/msfilter/svxmsbas.cxx svx/source/msfilter/svxmsbas.cxx
+index df541c2..a1b9869 100644
+--- svx/source/msfilter/svxmsbas.cxx
++++ svx/source/msfilter/svxmsbas.cxx
+@@ -91,7 +91,7 @@ int SvxImportMSVBasic::Import( const Str
+ 		nRet |= 1;
+ 
+     if (bImport)
+-        ImportForms_Impl(rStorageName, rSubStorageName);
++        ImportForms_Impl(rStorageName, rSubStorageName, !bAsComment);
+ 
+ 	if( bCopy && CopyStorage_Impl( rStorageName, rSubStorageName ))
+ 		nRet |= 2;
+@@ -100,7 +100,7 @@ int SvxImportMSVBasic::Import( const Str
+ }
+ 
+ bool SvxImportMSVBasic::ImportForms_Impl(const String& rStorageName,
+-    const String& rSubStorageName)
++    const String& rSubStorageName, BOOL bVBAMode )
+ {
+     SvStorageRef xVBAStg(xRoot->OpenSotStorage(rStorageName,
+         STREAM_READWRITE | STREAM_NOCREATE | STREAM_SHARE_DENYALL));
+@@ -184,7 +184,17 @@ bool SvxImportMSVBasic::ImportForms_Impl
+                     xSF->createInstance(
+                        OUString(RTL_CONSTASCII_USTRINGPARAM(
+                            "com.sun.star.awt.UnoControlDialogModel"))), uno::UNO_QUERY);
+-
++                // #FIXME HACK - mark the Model with the VBA mode
++                // In vba mode the imported userform uses 100th mm as units
++                // or geometry 
++                // In non vba mode MAP_APPFONT is used ( same as normal basic
++                // dialogs
++                if ( bVBAMode )
++                {
++                    Reference<XPropertySet> xDlgProps(xDialog, UNO_QUERY); 
++                    if ( xDlgProps.is() )
++                        xDlgProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("VBAForm") ), uno::makeAny( sal_True ) );
++                }
+                 OCX_UserForm aForm(xVBAStg, *aIter, *aIter, xDialog, xSF );
+                 aForm.pDocSh = &rDocSh;
+                 sal_Bool bOk = aForm.Read(xTypes);
+diff --git toolkit/inc/toolkit/helper/property.hxx toolkit/inc/toolkit/helper/property.hxx
+index db61c94..1abcda6 100644
+--- toolkit/inc/toolkit/helper/property.hxx
++++ toolkit/inc/toolkit/helper/property.hxx
+@@ -190,6 +190,7 @@ namespace rtl {
+ #define BASEPROPERTY_CUSTOMUNITTEXT                 136  // ::rtl::OUString
+ #define BASEPROPERTY_ENABLEVISIBLE                  137  // sal_Bool
+ #define BASEPROPERTY_GROUPNAME                      138  // ::rtl::OUString
++#define BASEPROPERTY_VBAFORM                      139  // sal_Bool
+ 
+ // Keine gebundenen Properties, werden immer aus der Property BASEPROPERTY_FONTDESCRIPTOR entnommen.
+ #define BASEPROPERTY_FONTDESCRIPTORPART_START			1000
+diff --git toolkit/source/controls/dialogcontrol.cxx toolkit/source/controls/dialogcontrol.cxx
+index be06bbb..f976562 100644
+--- toolkit/source/controls/dialogcontrol.cxx
++++ toolkit/source/controls/dialogcontrol.cxx
+@@ -80,6 +80,7 @@ using namespace ::com::sun::star::lang;
+ using namespace ::com::sun::star::container;
+ using namespace ::com::sun::star::beans;
+ using namespace ::com::sun::star::util;
++using namespace ::com::sun::star::script;
+ using namespace toolkit;
+ 
+ #define PROPERTY_RESOURCERESOLVER ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ResourceResolver" ))
+@@ -289,6 +290,8 @@ UnoControlDialogModel::UnoControlDialogM
+ 	aBool <<= (sal_Bool) sal_True;
+ 	ImplRegisterProperty( BASEPROPERTY_MOVEABLE, aBool );
+ 	ImplRegisterProperty( BASEPROPERTY_CLOSEABLE, aBool );
++	aBool <<= (sal_Bool) sal_False;
++	ImplRegisterProperty( BASEPROPERTY_VBAFORM, aBool );
+ }
+ 
+ UnoControlDialogModel::UnoControlDialogModel( const UnoControlDialogModel& rModel )
+@@ -1475,17 +1478,32 @@ void UnoDialogControl::ImplSetPosSize( R
+ 	xP->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Width" ) ) ) >>= nWidth;
+ 	xP->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Height" ) ) ) >>= nHeight;
+ 
+-	// Currentley we are simply using MAP_APPFONT
++	// Currentley we are simply using MAP_APPFONT ( for normal Dialogs )
++	// and MAP_100TH_MM for imported Userforms
++	MapMode aMode( MAP_APPFONT );
++	sal_Bool bVBAForm = sal_False;
++	Reference< XPropertySet > xDlgModelProps( getModel(), UNO_QUERY );
++	if ( xDlgModelProps.is() )
++	{
++		try
++		{
++			xDlgModelProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "VBAForm" ) ) ) >>= bVBAForm;
++		}
++		catch( Exception& )
++		{
++		}
++	} 
++	if ( bVBAForm )
++		aMode = MapMode( MAP_100TH_MM );
+ 	OutputDevice*pOutDev = Application::GetDefaultDevice();
+-	DBG_ASSERT( pOutDev, "Missing Default Device!" );
+ 	if ( pOutDev )
+ 	{
+ 		::Size aTmp( nX, nY );
+-		aTmp = pOutDev->LogicToPixel( aTmp, MAP_APPFONT );
++		aTmp = pOutDev->LogicToPixel( aTmp, aMode );
+ 		nX = aTmp.Width();
+ 		nY = aTmp.Height();
+ 		aTmp = ::Size( nWidth, nHeight );
+-		aTmp = pOutDev->LogicToPixel( aTmp, MAP_APPFONT );
++		aTmp = pOutDev->LogicToPixel( aTmp, aMode );
+ 		nWidth = aTmp.Width();
+ 		nHeight = aTmp.Height();
+ 	}
+diff --git toolkit/source/helper/property.cxx toolkit/source/helper/property.cxx
+index a7fc25b..8d1ee74 100644
+--- toolkit/source/helper/property.cxx
++++ toolkit/source/helper/property.cxx
+@@ -271,7 +271,8 @@ ImplPropertyInfo* ImplGetPropertyInfos( 
+ 			DECL_PROP_2		( "InvokesStopNodeEditing",	TREE_INVOKESSTOPNODEEDITING, sal_Bool,		BOUND, MAYBEDEFAULT ),
+             DECL_PROP_2     ( "DialogSourceURL",        DIALOGSOURCEURL,        ::rtl::OUString,    BOUND, MAYBEDEFAULT ),
+             DECL_PROP_2     ( "URL",                    URL,                    ::rtl::OUString,    BOUND, MAYBEDEFAULT ),
+-            DECL_PROP_2     ( "EnableVisible",          ENABLEVISIBLE,          sal_Bool,    BOUND, MAYBEDEFAULT )
++            DECL_PROP_2     ( "EnableVisible",          ENABLEVISIBLE,          sal_Bool,    BOUND, MAYBEDEFAULT ),
++            DECL_PROP_2     ( "VBAForm",          VBAFORM,          sal_Bool,    BOUND, MAYBEDEFAULT ),
+             };
+ 			pPropertyInfos = aImplPropertyInfos;
+ 			nElements = sizeof( aImplPropertyInfos ) / sizeof( ImplPropertyInfo );
+diff --git xmlscript/source/xmldlg_imexp/xmldlg_import.cxx xmlscript/source/xmldlg_imexp/xmldlg_import.cxx
+index e4f6647..64131f7 100644
+--- xmlscript/source/xmldlg_imexp/xmldlg_import.cxx
++++ xmlscript/source/xmldlg_imexp/xmldlg_import.cxx
+@@ -1916,9 +1916,22 @@ Reference< xml::sax::XDocumentHandler > 
+     Reference< XModel > const & xDocument )
+     SAL_THROW( (Exception) )
+ {
++    DialogImport* pImport = new DialogImport( xContext, xDialogModel, xDocument );
++    uno::Reference< script::XBasicLibraryInfo > xVBAModeSource( pImport->getScriptLibraryInfo(), uno::UNO_QUERY ); 
++    uno::Reference< beans::XPropertySet > xDlgProps( xDialogModel, uno::UNO_QUERY );
++    OSL_TRACE("importDialogModel xVBAModeSource %d, xDialogModel %d", xVBAModeSource.is(), xDlgProps.is() );
++    if ( xVBAModeSource.is() && xVBAModeSource->getVBACompatMode() && xDlgProps.is() )
++    {
++        try
++        {
++            xDlgProps->setPropertyValue( OUSTR("VBAForm"), uno::makeAny( sal_True ) );
++        }
++        catch( Exception& )
++        {
++        }
++    }
+     return ::xmlscript::createDocumentHandler(
+-        static_cast< xml::input::XRoot * >(
+-            new DialogImport( xContext, xDialogModel, xDocument ) ) );
++        static_cast< xml::input::XRoot * >( pImport ) );
+ }
+ 
+ }

Added: trunk/patches/vba/native-export/vbainfo-import-export-support.diff
==============================================================================
--- (empty file)
+++ trunk/patches/vba/native-export/vbainfo-import-export-support.diff	Wed Oct 29 15:27:45 2008
@@ -0,0 +1,966 @@
+diff --git basic/source/basmgr/basmgr.cxx basic/source/basmgr/basmgr.cxx
+index 864a941..158c894 100644
+--- basic/source/basmgr/basmgr.cxx
++++ basic/source/basmgr/basmgr.cxx
+@@ -71,6 +71,7 @@
+ #include <com/sun/star/script/ModuleInfo.hpp>
+ #include <com/sun/star/script/ModuleType.hpp>
+ #include <com/sun/star/script/XBasicLibraryInfo.hpp>
++#include <com/sun/star/script/XVBALibraryListener.hpp>
+ 
+ #include <cppuhelper/implbase1.hxx>
+ 
+@@ -194,6 +195,54 @@ public:
+ 		throw(::com::sun::star::uno::RuntimeException);
+ };
+ 
++//typedef cppu::ImplInheritanceHelper1< BasMgrContainerListenerImpl, XVBALibraryListener > LibListenerBase;
++
++typedef ::cppu::WeakImplHelper1< XVBALibraryListener > LibListenerBase;
++
++class LibraryListener : public LibListenerBase
++{
++    BasicManager* mpMgr;
++    ::rtl::OUString maLibName;
++    std::auto_ptr< BasMgrContainerListenerImpl > mpListener;
++public:
++
++LibraryListener( BasicManager* pMgr, ::rtl::OUString aLibName ) : mpMgr( pMgr ), maLibName( aLibName )
++{
++    mpListener.reset( new BasMgrContainerListenerImpl( pMgr, aLibName ) );
++}
++// XEventListener
++virtual void SAL_CALL disposing( const  ::com::sun::star::lang::EventObject& Source ) throw(::com::sun::star::uno::RuntimeException)
++{
++    if ( mpListener.get() )
++        mpListener->disposing( Source ); 
++}
++
++// XVBALibraryListener
++virtual void SAL_CALL elementInserted( const ::com::sun::star::container::ContainerEvent& Event ) throw(::com::sun::star::uno::RuntimeException)
++{
++    if ( mpListener.get() )
++        mpListener->elementInserted( Event ); 
++}
++
++virtual void SAL_CALL elementReplaced( const ::com::sun::star::container::ContainerEvent& Event ) throw(::com::sun::star::uno::RuntimeException)
++{
++    if ( mpListener.get() )
++        mpListener->elementReplaced( Event ); 
++}
++virtual void SAL_CALL elementRemoved( const ::com::sun::star::container::ContainerEvent& Event ) throw(::com::sun::star::uno::RuntimeException)
++{
++    if ( mpListener.get() )
++        mpListener->elementRemoved( Event ); 
++}
++
++void modeChanged( sal_Bool mode ) throw( RuntimeException ) 
++{ 
++    OSL_TRACE("**** vba mode changed %d", mode );
++    StarBASIC* pLib = mpMgr->GetLib( maLibName );
++    if ( pLib )
++        pLib->SetVBAEnabled( mode );
++}
++};
+ 
+ //============================================================================
+ // BasMgrContainerListenerImpl
+@@ -219,9 +268,12 @@ void BasMgrContainerListenerImpl::insert
+ 	if( xLibContainer.is() )
+ 	{
+ 		// Register listener for library
++//		Reference< XContainerListener > xLibraryListener
++//			= static_cast< XContainerListener* >
++//				( new BasMgrContainerListenerImpl( pMgr, aLibName ) );
+ 		Reference< XContainerListener > xLibraryListener
+ 			= static_cast< XContainerListener* >
+-				( new BasMgrContainerListenerImpl( pMgr, aLibName ) );
++				( new LibraryListener( pMgr, aLibName ) );
+ 		xLibContainer->addContainerListener( xLibraryListener );
+ 	}
+ 
+@@ -399,7 +451,6 @@ void SAL_CALL BasMgrContainerListenerImp
+ 	}
+ }
+ 
+-
+ //=====================================================================
+ 
+ class BasicErrorManager
+diff --git basic/source/inc/namecont.hxx basic/source/inc/namecont.hxx
+index f2760b8..fec20e6 100644
+--- basic/source/inc/namecont.hxx
++++ basic/source/inc/namecont.hxx
+@@ -176,6 +176,7 @@ public:
+ 	virtual void SAL_CALL removeContainerListener( const ::com::sun::star::uno::Reference< 
+ 		::com::sun::star::container::XContainerListener >& xListener ) 
+ 			throw (::com::sun::star::uno::RuntimeException);
++    ::cppu::OInterfaceContainerHelper& getListeners() { return maListenerContainer; }
+ };
+ 
+ //============================================================================
+@@ -576,7 +577,7 @@ protected:
+             void        implSetModified( sal_Bool _bIsModified );
+ typedef std::hash_map< rtl::OUString, com::sun::star::script::ModuleInfo, ::rtl::OUStringHash, ::std::equal_to< ::rtl::OUString > > NameToInfoHash;
+     NameToInfoHash hBasicInfo;
+-
++    ::cppu::OInterfaceContainerHelper& getListeners() { return maNameContainer.getListeners(); }
+ private:
+     /** checks whether the lib is readonly, or a readonly link, throws an IllegalArgumentException if so
+     */
+diff --git basic/source/inc/scriptcont.hxx basic/source/inc/scriptcont.hxx
+index 9a7bb87..9afd182 100644
+--- basic/source/inc/scriptcont.hxx
++++ basic/source/inc/scriptcont.hxx
+@@ -153,7 +153,6 @@ class SfxScriptLibrary : public SfxLibra
+ 	sal_Bool mbLoadedSource;
+ 	sal_Bool mbLoadedBinary;
+ 	sal_Bool mbVBA;
+-
+ 	// Provide modify state including resources
+ 	virtual sal_Bool isModified( void );
+ 	virtual void storeResources( void );
+@@ -195,6 +194,7 @@ public:
+ 		throw(::com::sun::star::container::NoSuchElementException, 
+ 			  ::com::sun::star::lang::WrappedTargetException, 
+ 			  ::com::sun::star::uno::RuntimeException);
++    // Methods XContainer
+     static bool containsValidModule( const ::com::sun::star::uno::Any& _rElement );
+     DECLARE_XINTERFACE()
+     DECLARE_XTYPEPROVIDER()
+diff --git basic/source/uno/namecont.cxx basic/source/uno/namecont.cxx
+index a777d23..2ba2ca5 100644
+--- basic/source/uno/namecont.cxx
++++ basic/source/uno/namecont.cxx
+@@ -102,6 +102,58 @@ using namespace osl;
+ 
+ using com::sun::star::uno::Reference;
+ 
++// #TODO move this to SfxLibrary ? probably we need to to gaurantee
++// consistency 
++::xmlscript::ObjectModuleDescHash lcl_getObjModDescHash( SfxLibrary& rLib )
++{
++	Reference< XNameContainer > xNameContainer( &rLib );
++	Reference< XBasicLibraryInfo > xLibInfo( xNameContainer, UNO_QUERY );
++	uno::Sequence< ::rtl::OUString > sModuleNames = rLib.getElementNames();
++	sal_Int32 nElem = sModuleNames.getLength();
++	::xmlscript::ObjectModuleDescHash hResult;
++	for ( sal_Int32 i = 0; xLibInfo.is() && i < nElem; ++i )
++	{
++		rtl::OUString sCodeName( sModuleNames[ i ] );
++		ModuleInfo mInfo = xLibInfo->getModuleInfo( sCodeName );
++		::xmlscript::ObjectModuleDesc aDesc;
++		aDesc.mnModuleType = mInfo.ModuleType;
++		switch ( mInfo.ModuleType )
++		{
++			case ModuleType::Form:
++				aDesc.msObjectName = sCodeName;
++				hResult[ sCodeName ] = aDesc;
++				break;
++			case ModuleType::Document:
++			{
++				Reference< XServiceInfo > xSI( mInfo.ModuleObject, UNO_QUERY );
++				if ( xSI.is() && xSI->supportsService( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "org.openoffice.excel.Workbook" ) ) ) )
++					aDesc.msObjectName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ThisWorkbook" ) ); 
++				else
++				{
++					SbUnoObjectRef pSbUnoObject = new SbUnoObject( String(), uno::makeAny( mInfo.ModuleObject ) );
++					SbxVariable* pVar = pSbUnoObject->Find( String( RTL_CONSTASCII_USTRINGPARAM("Name") ), SbxCLASS_DONTCARE );
++					if ( pVar )
++					{
++						pVar->Broadcast( SBX_HINT_DATAWANTED );
++						if ( pVar->SbxValue::GetType() == SbxSTRING )
++						{
++							aDesc.msObjectName = pVar->GetString();
++						}
++					}
++				}
++				hResult[ sCodeName ] = aDesc;
++			}
++			case ModuleType::Class:
++			case ModuleType::Normal:
++				break; // no codenames for these
++			default:
++				break; // shouldn't get here ( #TODO assertion or whatever )
++		}
++	}
++	return hResult;
++}
++
++
+ // #i34411: Flag for error handling during migration 
+ static bool GbMigrationSuppressErrors = false;
+ 
+@@ -896,6 +948,19 @@ sal_Bool SfxLibraryContainer::init_Impl(
+ 				    {
+ 					    OUString aIndexFileName;
+ 					    sal_Bool bLoaded = implLoadLibraryIndexFile( pImplLib, rLib, xLibraryStor, aIndexFileName );
++
++		if ( rLib.aName.equalsAscii("Standard") )
++		{
++			OSL_TRACE("*** iteration %d have got Standard Library**** VBA MODE is %d", i, rLib.bVBAMode );
++						// can't use the api here ( because setVBACompat will try to 
++						// convert the Libraries )
++			Reference< XNameContainer > xLib( pImplLib );
++            Reference< XBasicLibraryInfo > xLibInfo( xLib, UNO_QUERY );
++            if ( xLibInfo.is() )
++				xLibInfo->setVBACompatMode( rLib.bVBAMode );
++
++		}
++
+ 					    if( bLoaded && aLibName != rLib.aName )
+ 					    {
+ 						    OSL_ENSURE( 0, "Different library names in library"
+@@ -1142,6 +1207,14 @@ sal_Bool SfxLibraryContainer::init_Impl(
+ 						/*sal_Bool bReadIndexFile =*/ implLoadLibraryIndexFile
+ 							( pNewLib, aLibDesc, xDummyStor, pNewLib->maLibInfoFileURL );
+ 						implImportLibDescriptor( pNewLib, aLibDesc );
++						if( aLibName == aStandardStr )
++						{
++							// can't use the api here ( because setVBACompat will try to 
++							// convert the Libraries )
++							Reference< XBasicLibraryInfo > xLibInfo( xLib, UNO_QUERY );
++							if ( xLibInfo.is() )
++								xLibInfo->setVBACompatMode( aLibDesc.bVBAMode );
++						}
+ 					}
+ 				}
+ 				mxSFI->kill( aPrevFolder );
+@@ -1724,15 +1797,47 @@ void SfxLibraryContainer::implImportLibD
+ 	    const OUString* pElementNames = rLib.aElementNames.getConstArray();
+             Reference< XNameContainer > xLib( pLib );
+             Reference< XBasicLibraryInfo > xLibInfo( xLib, UNO_QUERY );
++            ::xmlscript::ObjectModuleDescHash::iterator it_end = rLib.hModuleTypeDesc.end();
+ 	    Any aDummyElement = createEmptyLibraryElement();
+ 	    for( sal_Int32 i = 0 ; i < nElementCount ; i++ )
+ 	    {
+                     // default the module type
+                     com::sun::star::script::ModuleInfo mInfo;
+                     mInfo.ModuleType = ModuleType::Normal;         
++                    if ( xLibInfo.is() && xLibInfo->getVBACompatMode() ) 
++                    {
++                        ::xmlscript::ObjectModuleDescHash::iterator it = rLib.hModuleTypeDesc.find( pElementNames[i] );
++                    
++                        mInfo.ModuleName = pElementNames[i];
++                        if ( it != it_end )
++                        {
++                            mInfo.ModuleType = it->second.mnModuleType;
++                            // hack for userform, needs to know about the document
++                            // well really it needs the dialog library
++                            if (  mInfo.ModuleType == ModuleType::Form )
++                                mInfo.ModuleObject = mxOwnerDocument;
++                            else
++                            {
++                                try
++                                {
++                                    Reference< XMultiServiceFactory> xSF( mxOwnerDocument.get(), uno::UNO_QUERY);
++                                    uno::Reference< container::XNameAccess > xVBACodeNamedObjectAccess;
++    				    if ( xSF.is() )
++				        xVBACodeNamedObjectAccess.set( xSF->createInstance( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "org.openoffice.vba.VBAObjectModuleObjectProvider"))), uno::UNO_QUERY );    
++                                    // get the api object for the codename
++                                    if ( xVBACodeNamedObjectAccess.is() )
++                                        mInfo.ModuleObject.set( xVBACodeNamedObjectAccess->getByName( mInfo.ModuleName ), uno::UNO_QUERY );
++                                }
++                                catch( Exception& e )
++                                { 
++                                    DBG_UNHANDLED_EXCEPTION();
++                                }
+ 
+-		    pLib->maNameContainer.insertByName( pElementNames[i], aDummyElement );
++                            }
++                        }
++                    }
+                     pLib->hBasicInfo[  pElementNames[i] ] = mInfo;
++					pLib->maNameContainer.insertByName( pElementNames[i], aDummyElement );
+ 	    }
+         pLib->mbPasswordProtected = rLib.bPasswordProtected;
+         pLib->mbReadOnly = rLib.bReadOnly;
+@@ -1856,6 +1961,33 @@ void SfxLibraryContainer::storeLibraries
+ 		rLib.bPreload = pImplLib->mbPreload;
+ 		rLib.bPasswordProtected = pImplLib->mbPasswordProtected;
+ 		rLib.aElementNames = pImplLib->getElementNames();
++		// #FIXME the codenames probably should be in the LibDescriptor 
++		// ok there should be a special code name for the document ( e.g. ThisWorkbook, ThisDocument etc.) this probably should exist in LibDescriptorArray
++		// hmm there possibly could be a problem distinguising that on
++		// excel import ( because it is just another Document Module )
++		// Hmm but also vba mode should only really be relevant for Standand 
++		// Library ( and I would say no other libraries should even exist )
++		// so, leaving for the moment
++		if ( pName->equals( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Standard") ) ) )
++		{
++#if 0
++// until we by default remove supporting the Option VBASupport thingy in the
++// source we can't trust xLibInfo because it is intended that the mode
++// is set only via the api ( and not internally )
++            Reference< XNameContainer > xNameContainer( pImplLib );
++            Reference< XBasicLibraryInfo > xLibInfo( xNameContainer, UNO_QUERY );
++			rLib.bVBAMode = xLibInfo.is() ? xLibInfo->getVBACompatMode() : sal_False;
++#else
++			BasicManager* pBasicMgr = getBasicManager();
++			StarBASIC* pBasicLib = pBasicMgr ? pBasicMgr->GetLib( String( RTL_CONSTASCII_USTRINGPARAM("Standard") ) ) : NULL;
++			Reference< XModel > xDocument( mxOwnerDocument.get(), UNO_QUERY );
++			rLib.bVBAMode = xDocument.is() && pBasicLib ?  pBasicLib->isVBAEnabled() : sal_False;
++#endif
++			if ( !rLib.bVBAMode )
++				rLib.hModuleTypeDesc = ::xmlscript::ObjectModuleDescHash();
++			else
++				rLib.hModuleTypeDesc = lcl_getObjModDescHash( *pImplLib );
++		}
+ 
+ 		if( pImplLib->implIsModified() || bComplete )
+ 		{
+diff --git basic/source/uno/sbservices.cxx basic/source/uno/sbservices.cxx
+index a2a4ded..aa076ea 100644
+--- basic/source/uno/sbservices.cxx
++++ basic/source/uno/sbservices.cxx
+@@ -43,6 +43,7 @@ namespace basic
+     //--------------------------------------------------------------------
+     extern void createRegistryInfo_SfxDialogLibraryContainer();
+     extern void createRegistryInfo_SfxScriptLibraryContainer();
++    extern void createRegistryInfo_PersistedReadOnlyCodeNames();
+ 
+     static void initializeModule()
+     {
+@@ -54,6 +55,7 @@ namespace basic
+             {
+                 createRegistryInfo_SfxDialogLibraryContainer();
+                 createRegistryInfo_SfxScriptLibraryContainer();
++                createRegistryInfo_PersistedReadOnlyCodeNames();
+             }
+         }
+     }
+diff --git basic/source/uno/scriptcont.cxx basic/source/uno/scriptcont.cxx
+index e64041a..0d16c46 100644
+--- basic/source/uno/scriptcont.cxx
++++ basic/source/uno/scriptcont.cxx
+@@ -58,6 +58,7 @@
+ #include <tools/urlobj.hxx>
+ 
+ #include <com/sun/star/script/ModuleSourceInfo.hpp>
++#include <com/sun/star/script/XVBALibraryListener.hpp>
+ #include <svtools/pathoptions.hxx>
+ #include <svtools/sfxecode.hxx>
+ #include <svtools/ehdl.hxx>
+@@ -1064,6 +1065,11 @@ SfxScriptLibraryContainer:: HasExecutabl
+ 
+ //============================================================================
+ // Service
++class PersistedReadOnlyCodeNames;
++void createRegistryInfo_PersistedReadOnlyCodeNames()
++{
++    static OAutoRegistration< PersistedReadOnlyCodeNames > aAutoRegistration;
++}
+ void createRegistryInfo_SfxScriptLibraryContainer()
+ {
+     static OAutoRegistration< SfxScriptLibraryContainer > aAutoRegistration;
+@@ -1136,6 +1142,7 @@ SfxScriptLibrary::SfxScriptLibrary( Modi
+     , mbLoadedSource( sal_False )
+     , mbLoadedBinary( sal_False )
+     , mbVBA( sal_False )
++
+ {
+ }
+ 
+@@ -1151,7 +1158,28 @@ SfxScriptLibrary::getVBACompatMode() thr
+ void SAL_CALL 
+ SfxScriptLibrary::setVBACompatMode( ::sal_Bool _vbacompatmodeon ) throw (RuntimeException)
+ {
++    bool triggerModeChange = ( mbVBA != _vbacompatmodeon );
+     mbVBA = _vbacompatmodeon;
++    if ( triggerModeChange )
++    {
++        implSetModified( true );
++        OInterfaceIteratorHelper aIterator( getListeners() );
++        while( aIterator.hasMoreElements() )
++        {
++            Reference< XInterface > xIface = aIterator.next();
++            Reference< XVBALibraryListener > xListener( xIface, UNO_QUERY );
++            if ( xListener.is() )
++            {
++                try
++                {
++                    xListener->modeChanged( mbVBA );           
++                }
++                catch( Exception& )
++                {
++                }
++            }
++        }
++    }
+ }
+ 
+ // Methods
+@@ -1258,7 +1286,134 @@ bool SAL_CALL SfxScriptLibrary::isLibrar
+ {
+     return SfxScriptLibrary::containsValidModule( aElement );
+ }
++typedef ::cppu::WeakImplHelper3< container::XNameAccess, lang::XInitialization, lang::XServiceInfo > ReadOnlyCodeNames_BASE;
+ 
++// XNameAccess, codename to/from objectnames
++class PersistedReadOnlyCodeNames : ReadOnlyCodeNames_BASE
++{
++typedef std::hash_map< rtl::OUString, rtl::OUString, ::rtl::OUStringHash, ::std::equal_to< ::rtl::OUString > > CodeNameHash;
++
++    CodeNameHash mCodeNameToObjectNames;
++public:
++    PersistedReadOnlyCodeNames()
++    {
++    }
++    // Methods - XInitialise
++    virtual void SAL_CALL initialize( const uno::Sequence< uno::Any >& aArguments ) throw (uno::Exception, uno::RuntimeException)
++    {
++        if ( !aArguments.getLength() )
++            throw RuntimeException();
++        Reference< document::XStorageBasedDocument > xDocument( aArguments[ 0 ], uno::UNO_QUERY_THROW ); 
++        Reference< embed::XStorage > xDocStorage; 
++        try
++        {
++            Reference< XMultiServiceFactory > xMSF = comphelper::getProcessServiceFactory();
++            Reference< XServiceInfo > xSI( xDocument, UNO_QUERY_THROW );
++            if ( xSI->supportsService( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.document.OfficeDocument" ) ) ) )
++                xDocStorage.set( xDocument->getDocumentStorage(), UNO_QUERY_THROW );
++            if ( xDocStorage.is() ) // not a 'real' document
++            {
++                rtl::OUString codeNameDir( RTL_CONSTASCII_USTRINGPARAM("Basic") );
++                rtl::OUString standardDir( RTL_CONSTASCII_USTRINGPARAM("Standard") );
++                rtl::OUString codeNameFile( RTL_CONSTASCII_USTRINGPARAM("script-lb.xml") );
++    
++                uno::Reference< embed::XStorage > xLibrariesStor( xDocStorage->openStorageElement( codeNameDir, embed::ElementModes::READ ), UNO_QUERY_THROW );
++                uno::Reference< embed::XStorage > xStandardStor( xLibrariesStor->openStorageElement( standardDir, embed::ElementModes::READ ), UNO_QUERY_THROW );
++                uno::Reference< io::XStream > xStream( xStandardStor->openStreamElement( codeNameFile, embed::ElementModes::READ ), UNO_QUERY_THROW );
++                uno::Reference< io::XInputStream > xInput( xStream->getInputStream(), UNO_QUERY_THROW );
++                ::xmlscript::LibDescriptor aLib;
++                InputSource source;
++                source.aInputStream = xInput;
++
++                Reference< XParser > xParser( xMSF->createInstance( OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.xml.sax.Parser") ) ), UNO_QUERY_THROW );
++                xParser->setDocumentHandler(  ::xmlscript::importLibraryCodeNames( aLib ) );
++                xParser->parseStream( source );
++                
++                ::xmlscript::ObjectModuleDescHash::iterator it_end = aLib.hModuleTypeDesc.end();
++                for ( ::xmlscript::ObjectModuleDescHash::iterator it = aLib.hModuleTypeDesc.begin(); it != it_end; ++it )
++                {
++                    if ( it->second.msObjectName.getLength() > 0 )
++                        mCodeNameToObjectNames[ it->second.msObjectName ] = it->first;
++                }
++            }
++        }
++        catch ( Exception& e )
++        {
++            OSL_TRACE("Urk, should never get here, help!!");
++        }
++    }
++    // Methods - XNameAccess
++    virtual uno::Any SAL_CALL getByName( const ::rtl::OUString& aName ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException)
++    {
++        ::xmlscript::CodeNameHash::iterator it = mCodeNameToObjectNames.find( aName );
++        if ( it == mCodeNameToObjectNames.end() )
++            throw container::NoSuchElementException();
++        return uno::makeAny( it->second );
++    }
++    virtual uno::Sequence< ::rtl::OUString > SAL_CALL getElementNames(  ) throw (uno::RuntimeException)
++    {
++        uno::Sequence< ::rtl::OUString > sNames( mCodeNameToObjectNames.size() );
++        ::rtl::OUString* pStr = sNames.getArray();
++        ::xmlscript::CodeNameHash::iterator it = mCodeNameToObjectNames.begin();
++        ::xmlscript::CodeNameHash::iterator it_end = mCodeNameToObjectNames.end();
++        for ( ; it != it_end ; ++it, ++pStr )
++            *pStr = it->first;    
++        return sNames;
++    }
++    virtual ::sal_Bool SAL_CALL hasByName( const ::rtl::OUString& aName ) throw (uno::RuntimeException)
++    {
++        return ( mCodeNameToObjectNames.find( aName ) != mCodeNameToObjectNames.end() );
++    }
++    // Methods - XElementAccess
++    virtual uno::Type SAL_CALL getElementType(  ) throw (uno::RuntimeException)
++    {
++        return ::getCppuType( (const rtl::OUString *)0 );
++    }
++    virtual ::sal_Bool SAL_CALL hasElements(  ) throw (uno::RuntimeException)
++    {
++        return ( mCodeNameToObjectNames.size() > 0 );
++    }
++    // Methods XServiceInfo
++    virtual ::rtl::OUString SAL_CALL getImplementationName( ) throw (::com::sun::star::uno::RuntimeException)
++    {
++        return getImplementationName_static(); 
++    }
++    virtual ::sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw (::com::sun::star::uno::RuntimeException)
++    {
++        uno::Sequence< rtl::OUString > sNames( getSupportedServiceNames() );
++        rtl::OUString* pStr = sNames.getArray(); 
++        rtl::OUString* pEnd = ( sNames.getArray() + sNames.getLength() ); 
++        for ( ; pStr != pEnd ; ++pStr )
++        {
++            if ( (*pStr).equals( ServiceName ) )
++                return sal_True; 
++        } 
++        return sal_False;
++    }
++    virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) throw (::com::sun::star::uno::RuntimeException)
++    {
++        return getSupportedServiceNames_static();
++    }
++    // Service
++    static ::com::sun::star::uno::Sequence< ::rtl::OUString > getSupportedServiceNames_static()
++    {
++        uno::Sequence< rtl::OUString > sServiceNames(1);
++        sServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("org.openoffice.vba.PersistedCodeNames"));
++        return sServiceNames;
++    }
++    static ::rtl::OUString getImplementationName_static()
++    {
++         static OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("PersistedReadOnlyCodeNames") );
++         return sImplName;
++    }
++
++    static Reference< XInterface > SAL_CALL Create ( const Reference< XComponentContext >& xServiceManager ) throw( Exception )
++    {
++        Reference< XInterface > xRet =
++        static_cast< XInterface* >( static_cast< OWeakObject* >( new PersistedReadOnlyCodeNames() ));
++        return xRet;
++    }
++};
+ //============================================================================
+ 
+ }   // namespace basic
+diff --git offapi/com/sun/star/script/XVBALibraryListener.idl offapi/com/sun/star/script/XVBALibraryListener.idl
+new file mode 100644
+index 0000000..0c9a637
+--- /dev/null
++++ offapi/com/sun/star/script/XVBALibraryListener.idl
+@@ -0,0 +1,16 @@
++#ifndef __com_sun_star_script_XVBALibraryListener_idl__ 
++#define __com_sun_star_script_XVBALibraryListener_idl__ 
++  
++#ifndef __com_sun_star_uno_XInterface_idl__ 
++#include <com/sun/star/uno/XInterface.idl> 
++#endif 
++#include <com/sun/star/container/XContainerListener.idl> 
++#endif 
++module com {  module sun {  module star {  module script {  
++  
++interface XVBALibraryListener: ::com::sun::star::container::XContainerListener
++{ 
++    void modeChanged( [in] boolean mode );
++  
++}; }; }; };  
++}; 
+diff --git offapi/com/sun/star/script/makefile.mk offapi/com/sun/star/script/makefile.mk
+index ea9bbd1..cfdf281 100644
+--- offapi/com/sun/star/script/makefile.mk
++++ offapi/com/sun/star/script/makefile.mk
+@@ -52,6 +52,8 @@ IDLFILES=\
+ 	XPersistentLibraryContainer.idl\
+ 	XStorageBasedLibraryContainer.idl\
+ 	XLibraryQueryExecutable.idl \
++	XBasicLibraryInfo.idl \
++	XVBALibraryListener.idl \
+ 	ModuleSizeExceededRequest.idl\
+ 
+ # ------------------------------------------------------------------
+diff --git sc/inc/document.hxx sc/inc/document.hxx
+index 35fd858..8b608f1 100644
+--- sc/inc/document.hxx
++++ sc/inc/document.hxx
+@@ -34,6 +34,7 @@
+ 
+ #include <vcl/prntypes.hxx>
+ #include <vcl/timer.hxx>
++#include <com/sun/star/container/XNameAccess.hpp>
+ #include <com/sun/star/uno/Reference.hxx>
+ #include <vos/ref.hxx>
+ #include "scdllapi.h"
+@@ -319,7 +320,7 @@ private:
+ 	Timer				aTrackTimer;
+ 
+     com::sun::star::uno::Reference< com::sun::star::document::XVbaEventsHelper > mxVbaEventsHelper;
+-
++        com::sun::star::uno::Reference< com::sun::star::container::XNameAccess > mxCodeNames;
+ public:
+     ScTabOpList         aTableOpList;		            // list of ScInterpreterTableOpParams currently in use
+     ScInterpreterTableOpParams  aLastTableOpParams;     // remember last params
+@@ -439,6 +440,7 @@ public:
+ 								SfxObjectShell* pDocShell = NULL );
+ 					~ScDocument();
+ 
++    com::sun::star::uno::Reference< com::sun::star::container::XNameAccess > GetPersistedCodeNames() throw( com::sun::star::uno::RuntimeException );
+ 	inline ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >
+ 					GetServiceManager() const { return xServiceManager; }
+ 
+diff --git sc/source/core/data/documen2.cxx sc/source/core/data/documen2.cxx
+index aa0bafd..e867e99 100644
+--- sc/source/core/data/documen2.cxx
++++ sc/source/core/data/documen2.cxx
+@@ -263,6 +263,7 @@ ScDocument::ScDocument( ScDocumentMode	e
+ 
+ 	aTrackTimer.SetTimeoutHdl( LINK( this, ScDocument, TrackTimeHdl ) );
+ 	aTrackTimer.SetTimeout( 100 );
++	aDocCodeName = String( RTL_CONSTASCII_USTRINGPARAM("ThisWorkbook") );
+ }
+ 
+ 
+diff --git sc/source/core/data/document.cxx sc/source/core/data/document.cxx
+index a94a264..e94e4f7 100644
+--- sc/source/core/data/document.cxx
++++ sc/source/core/data/document.cxx
+@@ -52,6 +52,7 @@
+ #include <unotools/charclass.hxx>
+ #include <unotools/transliterationwrapper.hxx>
+ #include <tools/tenccvt.hxx>
++#include <comphelper/processfactory.hxx>
+ 
+ #include "document.hxx"
+ #include "table.hxx"
+@@ -4485,5 +4486,32 @@ BOOL ScDocument::NeedPageResetAfterTab( 
+ 	return FALSE;		// sonst nicht
+ }
+ 
++using namespace ::com::sun::star;
++
++uno::Reference< container::XNameAccess > 
++ScDocument::GetPersistedCodeNames() throw( uno::RuntimeException )
++{
++    SfxObjectShell* pObjShell = GetDocumentShell();
++    if ( pShell && !mxCodeNames.is() )
++    {
++        uno::Sequence< uno::Any > aArgs( 1 );
++        aArgs[ 0 ] = uno::makeAny( pObjShell->GetModel() );
++        mxCodeNames.set( ::comphelper::getProcessServiceFactory()->createInstanceWithArguments(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("org.openoffice.vba.PersistedCodeNames")), aArgs),  uno::UNO_QUERY );
++        if ( mxCodeNames.is() )
++        {
++            rtl::OUString sWorkbook( RTL_CONSTASCII_USTRINGPARAM("ThisWorkbook") );
++            if ( mxCodeNames->hasByName( sWorkbook ) )
++            {
++		
++                rtl::OUString sCodeName;
++                mxCodeNames->getByName( sWorkbook ) >>= sCodeName;
++                SetCodeName( sCodeName );
++            }
++        }
++    }
++    return mxCodeNames;
++}
++
++
+ 
+ 
+diff --git sc/source/filter/xml/xmlsubti.cxx sc/source/filter/xml/xmlsubti.cxx
+index c56f867..34bcce3 100644
+--- sc/source/filter/xml/xmlsubti.cxx
++++ sc/source/filter/xml/xmlsubti.cxx
+@@ -246,6 +246,27 @@ void ScMyTables::NewSheet(const rtl::OUS
+ 									}
+ 								}
+ 						}
++
++						ScDocument *pDoc = ScXMLConverter::GetScDocument(rImport.GetModel());
++						// Codenames need to be set as sheets are created and read
++						if ( pDoc  )
++						{
++							String sName;
++							pDoc->GetName( nCurrentSheet, sName );
++							OSL_TRACE("** import processing %s", rtl::OUStringToOString( sName, RTL_TEXTENCODING_UTF8 ).getStr() );
++	                        rtl::OUString sOUName( sName );
++							uno::Reference< container::XNameAccess > xCodeNames( pDoc->GetPersistedCodeNames() );
++							if( xCodeNames.is() && xCodeNames->hasByName( sName ) )
++							{
++								rtl::OUString sOUSCodeName;
++								xCodeNames->getByName( sName ) >>= sOUSCodeName;
++							    OSL_TRACE("** import processing setting codename %s for %s", rtl::OUStringToOString( sOUSCodeName, RTL_TEXTENCODING_UTF8 ).getStr(), rtl::OUStringToOString( sName, RTL_TEXTENCODING_UTF8 ).getStr() );
++								rImport.LockSolarMutex();
++								String sCodeName( sOUSCodeName );
++								pDoc->SetCodeName( nCurrentSheet, sCodeName );		
++								rImport.UnlockSolarMutex();
++							}
++						}
+ 						rImport.SetTableStyle(sStyleName);
+ 
+                         if ( sStyleName.getLength() )
+diff --git sc/source/ui/vba/vbaeventshelper.cxx sc/source/ui/vba/vbaeventshelper.cxx
+index a315af0..b4d0bd9 100644
+--- sc/source/ui/vba/vbaeventshelper.cxx
++++ sc/source/ui/vba/vbaeventshelper.cxx
+@@ -620,7 +620,7 @@ String ScVbaEventsHelper::getSheetModule
+ {
+ 	ScExtDocOptions* pExtOptions = pDoc->GetExtDocOptions();
+ 	String aCodeName;
+-	pDoc->GetName( nTab, aCodeName);
++	pDoc->GetCodeName( nTab, aCodeName);
+ 	// Use code name if that exists
+ 	if ( pExtOptions )
+ 		aCodeName = pExtOptions->GetCodeName( nTab );
+diff --git xmlscript/inc/xmlscript/xmllib_imexp.hxx xmlscript/inc/xmlscript/xmllib_imexp.hxx
+index 9a3048f..93826a9 100644
+--- xmlscript/inc/xmlscript/xmllib_imexp.hxx
++++ xmlscript/inc/xmlscript/xmllib_imexp.hxx
+@@ -34,11 +34,21 @@
+ #include <com/sun/star/uno/Sequence.hxx>
+ 
+ #include "xmlscript/xmlns.h"
+-
++#include <hash_map>
++#include <com/sun/star/script/ModuleType.hpp>
+ 
+ namespace xmlscript
+ {
++struct ObjectModuleDesc
++{
++    rtl::OUString msObjectName;
++    sal_Int32 mnModuleType;
++ObjectModuleDesc() : mnModuleType( ::com::sun::star::script::ModuleType::Normal ) {}
++};
+ 
++typedef  std::hash_map< rtl::OUString,
++ObjectModuleDesc, ::rtl::OUStringHash,
++::std::equal_to< ::rtl::OUString > > ObjectModuleDescHash;
+ //==============================================================================
+ // Library container export
+ // HACK C++ struct to transport info. Later the container 
+@@ -51,10 +61,15 @@ struct LibDescriptor
+ 	sal_Bool bLink;
+ 	sal_Bool bReadOnly;
+ 	sal_Bool bPasswordProtected;
++	sal_Bool bVBAMode;
+ 	::com::sun::star::uno::Sequence< ::rtl::OUString > aElementNames;
+ 	sal_Bool bPreload;
++	ObjectModuleDescHash hModuleTypeDesc;
++	LibDescriptor(); 
+ };
+ 
++typedef std::hash_map< rtl::OUString, rtl::OUString, ::rtl::OUStringHash, ::std::equal_to< ::rtl::OUString > > CodeNameHash;
++
+ struct LibDescriptorArray
+ {
+     LibDescriptor* mpLibs;
+@@ -79,6 +94,11 @@ SAL_CALL exportLibraryContainer(
+ SAL_CALL importLibraryContainer( LibDescriptorArray* pLibArray )
+ 		SAL_THROW( (::com::sun::star::uno::Exception) );
+ 
++::com::sun::star::uno::Reference<
++    ::com::sun::star::xml::sax::XDocumentHandler >
++SAL_CALL importLibraryCodeNames( LibDescriptor& rLib )
++		SAL_THROW( (::com::sun::star::uno::Exception) );
++
+ 
+ void
+ SAL_CALL exportLibrary(
+diff --git xmlscript/source/xmllib_imexp/imp_share.hxx xmlscript/source/xmllib_imexp/imp_share.hxx
+index d602103..fdc0536 100644
+--- xmlscript/source/xmllib_imexp/imp_share.hxx
++++ xmlscript/source/xmllib_imexp/imp_share.hxx
+@@ -220,7 +220,6 @@ class LibrariesElement : public LibEleme
+     
+ protected:
+     vector< LibDescriptor > mLibDescriptors;
+-
+ public:
+     virtual Reference< xml::input::XElement > SAL_CALL startChildElement(
+         sal_Int32 nUid, OUString const & rLocalName,
+@@ -244,7 +243,7 @@ class LibraryElement : public LibElement
+ {
+ protected:
+     vector< OUString > mElements;
+-
++    ObjectModuleDescHash mObjectDescs;
+ public:
+ 
+     virtual Reference< xml::input::XElement > SAL_CALL startChildElement(
+diff --git xmlscript/source/xmllib_imexp/xmllib_export.cxx xmlscript/source/xmllib_imexp/xmllib_export.cxx
+index 4f6de54..2ab8182 100644
+--- xmlscript/source/xmllib_imexp/xmllib_export.cxx
++++ xmlscript/source/xmllib_imexp/xmllib_export.cxx
+@@ -44,6 +44,28 @@ namespace xmlscript
+ static OUString aTrueStr ( RTL_CONSTASCII_USTRINGPARAM("true") );
+ static OUString aFalseStr( RTL_CONSTASCII_USTRINGPARAM("false") );
+ 
++rtl::OUString lcl_getModuleTypeStringForType( sal_Int32 nModuleType )
++{
++	rtl::OUString sType;
++	switch( nModuleType )
++	{
++		case script::ModuleType::Document:
++			sType = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Document" ) );
++			break;
++		case script::ModuleType::Class:
++			sType = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Class" ) );
++			break;
++		case script::ModuleType::Form:
++			sType = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Form" ) );
++			break;
++		case script::ModuleType::Normal: // no need to set a module type
++		case script::ModuleType::Unknown:
++		default:
++			break;
++	}
++	return sType;
++}
++
+ //##################################################################################################
+ 
+ 
+@@ -73,11 +95,10 @@ SAL_CALL exportLibraryContainer(
+ 	pLibsElement->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM("xmlns:" XMLNS_XLINK_PREFIX) ),
+ 							    OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_XLINK_URI) ) );
+ 
+-
+-	xOut->ignorableWhitespace( OUString() );
++    int nLibCount = pLibArray->mnLibCount;
+ 	xOut->startElement( aLibrariesName, xAttributes );
++	xOut->ignorableWhitespace( OUString() );
+ 
+-    int nLibCount = pLibArray->mnLibCount;
+ 	for( sal_Int32 i = 0 ; i < nLibCount ; i++ )
+ 	{
+ 		LibDescriptor& rLib = pLibArray->mpLibs[i];
+@@ -107,7 +128,6 @@ SAL_CALL exportLibraryContainer(
+ 	        pLibElement->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_LIBRARY_PREFIX ":readonly") ),
+ 								        rLib.bReadOnly ? aTrueStr : aFalseStr );
+         }
+-
+ 		pLibElement->dump( xOut.get() );
+ 	}
+ 
+@@ -152,11 +172,15 @@ SAL_CALL exportLibrary(
+ 
+     if( rLib.bPreload )
+ 		pLibElement->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_LIBRARY_PREFIX ":preload") ), aTrueStr );
++// Basic/Library/script-xx.xml
++    if( rLib.bVBAMode )
++		pLibElement->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_LIBRARY_PREFIX ":vbaenabled") ), aTrueStr );
+ 
+ 	sal_Int32 nElementCount = rLib.aElementNames.getLength();
+ 	if( nElementCount )
+ 	{
+ 		const OUString* pElementNames = rLib.aElementNames.getConstArray();
++		
+ 		for( sal_Int32 i = 0 ; i < nElementCount ; i++ )
+ 		{
+ 			XMLElement* pElement = new XMLElement( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_LIBRARY_PREFIX ":element" ) ) );
+@@ -165,7 +189,16 @@ SAL_CALL exportLibrary(
+ 
+ 			pElement->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_LIBRARY_PREFIX ":name") ),
+ 										pElementNames[i] );
+-	
++			ObjectModuleDescHash::const_iterator it = rLib.hModuleTypeDesc.find( pElementNames[i] );
++			if ( it !=  rLib.hModuleTypeDesc.end() )
++			{
++				rtl::OUString sType = lcl_getModuleTypeStringForType( it->second.mnModuleType );
++				if ( sType.getLength() )
++				{
++					pElement->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_LIBRARY_PREFIX ":moduletype") ), sType );
++					pElement->addAttribute( OUString( RTL_CONSTASCII_USTRINGPARAM(XMLNS_LIBRARY_PREFIX ":objectname") ), it->second.msObjectName );
++				}
++			}
+ 			pLibElement->addSubElement( pElement );
+ 		}
+ 	}
+diff --git xmlscript/source/xmllib_imexp/xmllib_import.cxx xmlscript/source/xmllib_imexp/xmllib_import.cxx
+index b533d37..d1aa54d 100644
+--- xmlscript/source/xmllib_imexp/xmllib_import.cxx
++++ xmlscript/source/xmllib_imexp/xmllib_import.cxx
+@@ -44,7 +44,20 @@ namespace xmlscript
+ {
+ 
+ //##################################################################################################
+-
++sal_Int32 lcl_getModuleTypeForStringType( const rtl::OUString& rsType )
++{
++    // default to normal unknown
++    sal_Int32 nType = com::sun::star::script::ModuleType::Unknown;
++    if ( rsType.equalsIgnoreAsciiCase( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("class") ) ) )
++        nType = com::sun::star::script::ModuleType::Class;
++    else if ( rsType.equalsIgnoreAsciiCase( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("form") ) ) )
++        nType = com::sun::star::script::ModuleType::Form;
++    else if ( rsType.equalsIgnoreAsciiCase( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("document") ) ) )
++        nType = com::sun::star::script::ModuleType::Document;
++    else if ( rsType.equalsIgnoreAsciiCase( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("normal") ) ) )
++        nType = com::sun::star::script::ModuleType::Normal;
++    return nType;
++}
+ //__________________________________________________________________________________________________
+ Reference< xml::input::XElement > LibElementBase::getParent()
+     throw (RuntimeException)
+@@ -206,7 +219,10 @@ Reference< xml::input::XElement > Librar
+             &aDesc.bPreload,
+             OUString( RTL_CONSTASCII_USTRINGPARAM("preload") ),
+             xAttributes, XMLNS_LIBRARY_UID );
+-
++        getBoolAttr(
++            &aDesc.bVBAMode,
++            OUString( RTL_CONSTASCII_USTRINGPARAM("vbaenabled") ),
++            xAttributes, XMLNS_LIBRARY_UID );
+         return new LibraryElement( rLocalName, xAttributes, 0, this );
+     }
+     else
+@@ -265,7 +281,12 @@ Reference< xml::input::XElement > Librar
+             &aDesc.bPasswordProtected,
+             OUString( RTL_CONSTASCII_USTRINGPARAM("passwordprotected") ),
+             xAttributes, _pImport->XMLNS_LIBRARY_UID );
+-
++/*
++        getBoolAttr(
++            &aDesc.bVBAMode,
++            OUString( RTL_CONSTASCII_USTRINGPARAM("vbaenabled") ),
++            xAttributes, _pImport->XMLNS_LIBRARY_UID );
++*/
+         mLibDescriptors.push_back( aDesc );
+         return new LibraryElement( rLocalName, xAttributes, this, _pImport );
+     }
+@@ -312,6 +333,17 @@ Reference< xml::input::XElement > Librar
+         if (aValue.getLength())
+             mElements.push_back( aValue );
+ 
++        ObjectModuleDesc aDesc;
++	
++        aDesc.mnModuleType = lcl_getModuleTypeForStringType( 
++          xAttributes->getValueByUidName(
++            _pImport->XMLNS_LIBRARY_UID,
++            OUString( RTL_CONSTASCII_USTRINGPARAM("moduletype") ) ) );
++        aDesc.msObjectName = xAttributes->getValueByUidName(
++            _pImport->XMLNS_LIBRARY_UID,
++            OUString( RTL_CONSTASCII_USTRINGPARAM("objectname") ) );
++        if ( aValue.getLength() && aDesc.mnModuleType != ::com::sun::star::script::ModuleType::Unknown )
++             mObjectDescs[ aValue ] = aDesc;
+         return new LibElementBase( rLocalName, xAttributes, this, _pImport );
+     }
+     else
+@@ -335,6 +367,7 @@ void LibraryElement::endElement()
+     if( !pLib )
+         pLib = &static_cast< LibrariesElement* >( _pParent )->mLibDescriptors.back();
+     pLib->aElementNames = aElementNames;
++    pLib->hModuleTypeDesc = mObjectDescs;
+ }
+ 
+ 
+@@ -348,6 +381,15 @@ SAL_CALL importLibraryContainer( LibDesc
+         static_cast< xml::input::XRoot * >( new LibraryImport( pLibArray ) ) );
+ }
+ 
++
++Reference< ::com::sun::star::xml::sax::XDocumentHandler >
++SAL_CALL importLibraryCodeNames( LibDescriptor& rLib)
++        SAL_THROW( (Exception) )
++{
++    return importLibrary( rLib );
++}
++
++
+ //##################################################################################################
+ 
+ ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XDocumentHandler >
+@@ -360,6 +402,13 @@ SAL_CALL importLibrary( LibDescriptor& r
+ 
+ 
+ //##################################################################################################
++LibDescriptor::LibDescriptor()
++{
++    bLink = sal_False;
++    bReadOnly = sal_False;
++    bPasswordProtected = sal_False;
++    bVBAMode = sal_False;
++}
+ 
+ LibDescriptorArray::LibDescriptorArray( sal_Int32 nLibCount )
+ {



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]