Periodically calling a macro
Periodically calling a macro
Hello,
Once I open a spreadsheet I want to periodically call a macro (say once every second). The macro is in OOBasic....
Thanks for your help,
Saleem
Once I open a spreadsheet I want to periodically call a macro (say once every second). The macro is in OOBasic....
Thanks for your help,
Saleem
OpenOffice 3.4.0
Mac OS X 10.5.8
Mac OS X 10.5.8
Re: Periodically calling a macro
Implement a timer macro in some professional language and let it call your Basic code (or better transfer everything to some real language).
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Re: Periodically calling a macro
How can a C++ function implemented in an addin call an OOBasic Macro??
All I actually want to do is a perform a full recalculate every 3 seconds...
Saleem
All I actually want to do is a perform a full recalculate every 3 seconds...
Saleem
OpenOffice 3.4.0
Mac OS X 10.5.8
Mac OS X 10.5.8
Re: Periodically calling a macro
Do
ThisComponent.recalculateAll()
wait 3000
Loop
ThisComponent.recalculateAll()
wait 3000
Loop
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
- Charlie Young
- Volunteer
- Posts: 1559
- Joined: Fri May 14, 2010 1:07 am
Re: Periodically calling a macro
I see Villeroy has provided the Basic macro, but here's another version, which accepts the number of seconds as a parameter:saleem145 wrote:How can a C++ function implemented in an addin call an OOBasic Macro??
All I actually want to do is a perform a full recalculate every 3 seconds...
Saleem
Code: Select all
Sub CalcDoc(secs As Long)
Do While True
Wait(1000 * secs)
ThisComponent.calculateAll()
Loop
End Sub
Consider this idl
Code: Select all
long RecalcDocFromBasic([in] long secs, [in] ::com::sun::star::beans::XPropertySet docProps);
Then this implementation
Code: Select all
long SAL_CALL MyServiceImpl::RecalcDocFromBasic(long secs,const Reference<XPropertySet> & docProps )
throw (RuntimeException)
{
Sequence<Any> a(1);
Sequence<sal_Int16> b(0);
Sequence<Any> c(0);
Reference < XInterface > Desktop = rOfficeServiceManager->createInstance(OUString::createFromAscii( "com.sun.star.frame.Desktop" ));
Reference< XDesktop > xDesktop(Desktop, UNO_QUERY);
Reference< XComponent > xcomponent = xDesktop->getCurrentComponent();
Reference< XSpreadsheetDocument > oDoc (xcomponent, UNO_QUERY);
Reference<XScriptProviderSupplier> xSupplier(oDoc,UNO_QUERY);
Reference<XScriptProvider> xProvider = xSupplier->getScriptProvider();
Reference<XScript> calcScript = xProvider->getScript(OUString( RTL_CONSTASCII_USTRINGPARAM("vnd.sun.star.script:Standard.Module1.CalcDoc?language=Basic&location=document")));
a[0] <<= (sal_Int32) secs;
calcScript->invoke(a,b,c);
return secs;
}
Code: Select all
static Reference< XMultiServiceFactory > rOfficeServiceManager;
Code: Select all
Reference< XMultiServiceFactory > MyServiceImpl::rOfficeServiceManager;
Code: Select all
static void getServiceMgr(Reference< XComponentContext >);
Then externally
Code: Select all
void MyServiceImpl::getServiceMgr(Reference< XComponentContext > rComponentContext)
{
Reference< XMultiComponentFactory > rServiceManager = rComponentContext->getServiceManager();
rOfficeServiceManager = Reference< XMultiServiceFactory >(rServiceManager, UNO_QUERY);
}
Code: Select all
Reference< XInterface > SAL_CALL create_MyServiceImpl(
Reference< XComponentContext > const & xContext )
SAL_THROW( () )
{
MyServiceImpl::getServiceMgr(xContext);
return static_cast< lang::XTypeProvider * >( new MyServiceImpl() );
}
Code: Select all
=RECALCDOCFROMBASIC(3)
The CalcDoc macro is indeed started, but because it is in an infinite loop, the RECALCDOCFROMBASIC won't return until the macro terminates, which must be forced with Ctrl-Shift-Q (unless one wishes to force-close the document).
I think I know where this is going, and I am playing with a more interesting volatile function, so I'll have more to say at some point.
Apache OpenOffice 4.1.1
Windows XP
Windows XP
Re: Periodically calling a macro
Code: Select all
Sub CalcDoc(secs As Long)
Do While True
Wait(1000 * secs)
ThisComponent.calculateAll()
Loop
End Sub
OpenOffice 3.4.0
Mac OS X 10.5.8
Mac OS X 10.5.8
Re: Periodically calling a macro
That freezes your Basic-interpreter as long as it runs.saleem145 wrote:This is good enough for me. I can call the macro when I open the spreadsheet and am good. One question though -- will Wait cause the GUI to freeze up?? I think the macro might need to run in a seperate thread...I am going to try it...Code: Select all
Sub CalcDoc(secs As Long) Do While True Wait(1000 * secs) ThisComponent.calculateAll() Loop End Sub
Libreoffice 7.4 on Debian 12 (Bookworm) (on RaspberryPI4)
Libreoffice 7.6 flatpak on Debian 12 (Bookworm) (on RaspberryPI4)