[Solved] Macro that activate ctrl+s

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
koden
Posts: 40
Joined: Mon Jul 04, 2022 2:13 pm

[Solved] Macro that activate ctrl+s

Post 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).
Last edited by MrProgrammer on Sat Aug 13, 2022 4:31 am, edited 1 time in total.
Reason: Tagged ✓ [Solved] -- MrProgrammer, forum moderator
open office 4.1.11
User avatar
Villeroy
Volunteer
Posts: 31269
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Macro that activate ctrl+s

Post 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.
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
User avatar
Zizi64
Volunteer
Posts: 11353
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Macro that activate ctrl+s

Post 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 76 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.
Last edited by Zizi64 on Sat Aug 06, 2022 1:41 pm, edited 3 times in total.
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
User avatar
Zizi64
Volunteer
Posts: 11353
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Macro that activate ctrl+s

Post 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
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
User avatar
Zizi64
Volunteer
Posts: 11353
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Macro that activate ctrl+s

Post 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.
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
koden
Posts: 40
Joined: Mon Jul 04, 2022 2:13 pm

Re: Macro that activate ctrl+s

Post by koden »

Thanks... will have a look of the examples.
open office 4.1.11
User avatar
Zizi64
Volunteer
Posts: 11353
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Macro that activate ctrl+s

Post 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.
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
koden
Posts: 40
Joined: Mon Jul 04, 2022 2:13 pm

Re: Macro that activate ctrl+s

Post by koden »

yes I understood that...
Dont know Libre or what the diff. is compared to openoffice

But will look at it
open office 4.1.11
User avatar
Zizi64
Volunteer
Posts: 11353
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Macro that activate ctrl+s

Post 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
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
Bidouille
Volunteer
Posts: 574
Joined: Mon Nov 19, 2007 10:58 am
Location: France

Re: Macro that activate ctrl+s

Post 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
Attachments
AutoSave.ods
(9.92 KiB) Downloaded 83 times
koden
Posts: 40
Joined: Mon Jul 04, 2022 2:13 pm

Re: Macro that activate ctrl+s

Post 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.
open office 4.1.11
Post Reply