Page 1 of 1

[Solved] Macro that activate ctrl+s

Posted: Fri Aug 05, 2022 10:33 pm
by koden
is it possible to create macro that activate ctrl+s every time a cell is changed in a CALC document?
Or every time ENTER is hit (if the CELL version is not possible).

Re: Macro that activate ctrl+s

Posted: Fri Aug 05, 2022 10:47 pm
by Villeroy
If you would use a database, you would never have to save any file. A database stores every modifed row to disk when you move to another row.

Re: Macro that activate ctrl+s

Posted: Sat Aug 06, 2022 7:12 am
by Zizi64
is it possible to create macro that activate ctrl+s every time a cell is changed in a CALC document?
Or every time ENTER is hit (if the CELL version is not possible).
Yes, it is possible, but it means a too frequent saving procedure for a large spreadsheet document. It may become impossible to work with the document.
There are Event in the Customize feature: 'Modified' status was changed.
Assign your saving macro to it.

Be careful. An infinite loop can be created.


Modified Event.ods
Sample macro for the event 'Modified'.
(10.48 KiB) Downloaded 176 times
The sample document contains a sample macro, what saves the documents after every changing the document content.

Note: the macro was created IN LibreOffice FOR LibreOffice. Maybe the API and the Events in the Apache OpenOffice are different today.

Re: Macro that activate ctrl+s

Posted: Sat Aug 06, 2022 8:41 am
by Zizi64
if the CELL version is not possible
And you can write your own Listeners for a partial cell range. See Andrew Pitonyak's free macro books.
https://www.pitonyak.org/oo.php/

...or search in this Forum:
https://forum.openoffice.org/en/forum/s ... &sr=topics

Re: Macro that activate ctrl+s

Posted: Sun Aug 07, 2022 10:11 am
by Zizi64
Here is an 'improved' sample code of the macro.The Save procedure will be active after 10 change of the content.
Note (again): It works in the LibreOffice only.

Code: Select all

REM  *****  BASIC  *****
Option explicit

Global const myLimit = 10 'The Autosave works after 10 content change
Global myCounter as double

Sub myAutoSave
' AutoSave When Modified State Raised more than 10 times

 dim oDoc as object
 
	oDoc = ThisComponent
	if (oDoc.isModified) Then
		myCounter = myCounter + 0.5 'This increase command - somehow - will be run twice in a single loop 
		if myCounter >= myLimit then
			if (oDoc.hasLocation AND (Not oDoc.isReadOnly)) Then
        			oDoc.store()
        			myCounter = 0
			else
				oDoc.setModified(False)
			end if
		else
			oDoc.setModified(False)
		end if
	end if

End Sub
Note: The original "Content changed" display on the LibreOffice 'Save' icon becomes unusable when you apply this macro.

Re: Macro that activate ctrl+s

Posted: Sun Aug 07, 2022 12:50 pm
by koden
Thanks... will have a look of the examples.

Re: Macro that activate ctrl+s

Posted: Sun Aug 07, 2022 1:05 pm
by Zizi64
Thanks... will have a look of the examples.

__________________________
open office 4.1.11
You need install the LibreOffice for this task. At least a portable version of it.

Re: Macro that activate ctrl+s

Posted: Sun Aug 07, 2022 1:08 pm
by koden
yes I understood that...
Dont know Libre or what the diff. is compared to openoffice

But will look at it

Re: Macro that activate ctrl+s

Posted: Sun Aug 07, 2022 5:27 pm
by Zizi64
Dont know Libre or what the diff. is compared to openoffice
LibreOffice was forked of the OpenOffice at the version 3.3. LO has a much more active (volunteer) developer team. The latest Fresh version is 7.3.5, but it is better to use the latest Still version. LO has many new features and functions, modified appearance and behavior; there are fixed lots of bugs (and raised some new bugs)...

https://www.libreoffice.org/download/download/

https://en.wikipedia.org/wiki/LibreOffice#History

Re: Macro that activate ctrl+s

Posted: Thu Aug 11, 2022 9:17 pm
by Bidouille
Zizi64 wrote: Sun Aug 07, 2022 10:11 am Note (again): It works in the LibreOffice only.
This works with no problem under OpenOffice 4.1.13 and Windows 10

Re: Macro that activate ctrl+s

Posted: Fri Aug 12, 2022 12:01 pm
by koden
yes this is perfect :-)

 Edit: Discussion about editing the macro is continued in topic Edit a macro
-- MrProgrammer, forum moderator  

It's working fine.
But is it someone I can edit in?

maybe I would like to save after 5 cells and maybe remove the save box showing..

tried to go to tools > macros > administrate

but get stuck there

Assume I have to open it up in some kind of program to edit it.