[Solved] Macro to add date/time when cell in row changed

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
showbi
Posts: 3
Joined: Mon Oct 08, 2018 4:06 pm

[Solved] Macro to add date/time when cell in row changed

Post by showbi »

Hi Every one,
I am new in Macro coding and need your help on subjected topic.
How to write Macros code which add date/time in a cell when data is entered in another cell in the same row in LibreOffice calc [/b]
Last edited by Hagar Delest on Tue Oct 09, 2018 9:01 pm, edited 2 times in total.
Reason: tagged solved
LibreOffice Version: 5.1.6.2 on Ubuntu OS Version: :Linux 4.4
User avatar
Lupp
Volunteer
Posts: 3549
Joined: Sat May 31, 2014 7:05 pm
Location: München, Germany

Re: Macro code to add date/time when cell in row changed

Post by Lupp »

Welcome!
That's not as simple as you probably assume.
You will have to assign a handler to the sheet event 'Content changed'. That's not difficult at all in principle, but you need to be clear about your needs and your intentions first.

-1- What do you mean by "add" here? Should this read "insert?
-2- Data cannot only be entered into a cell via the keyboard one by one, but also by pasting and many at a time. What shall be done in such cases?
-3- What shall be done if data are edited / deleted?
-4- And ... (depending yon your answers to the above questions)

Whithout being precise concerning the mentioned questions any suggestions may result just in wasted time.
On Windows 10: LibreOffice 24.2 (new numbering) and older versions, PortableOpenOffice 4.1.7 and older, StarOffice 5.2
---
Lupp from München
showbi
Posts: 3
Joined: Mon Oct 08, 2018 4:06 pm

Re: Macro code to add date/time when cell in row changed

Post by showbi »

thanks for your prompt reply...
-1- What do you mean by "add" here? Should this read "insert?
ans:- i mean when ever data updated in the cell, the current date and time also update automatically.

-2- Data cannot only be entered into a cell via the keyboard one by one, but also by pasting and many at a time. What shall be done in such cases?
ans:- same rule should be apply any type of data entered date and time update automatically.

-3- What shall be done if data are edited / deleted?
ans:- only if data edited apply same rule for update date and time and if data deleted not required date and time update.
LibreOffice Version: 5.1.6.2 on Ubuntu OS Version: :Linux 4.4
User avatar
Zizi64
Volunteer
Posts: 11359
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Macro code to add date/time when cell in row changed

Post by Zizi64 »

Combined the informations and sample code snippets of these topics I just created this sample file below:
viewtopic.php?f=20&t=30516
viewtopic.php?f=20&t=85972
Event_ContentChanged.ods
(12.84 KiB) Downloaded 145 times
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
Lupp
Volunteer
Posts: 3549
Joined: Sat May 31, 2014 7:05 pm
Location: München, Germany

Re: Macro code to add date/time when cell in row changed

Post by Lupp »

The nice and compact code contained in the example above has some flaws, unfortunately. In specific it will throw an error if you call 'Del' for a non-contiguous selection (multi-selection) becasue the selection not supports some used services in this case.
(The oEvent object would pass the same CellRanges -regard the plural- instead of a single range expected.)

Since I had some routines for similar tasks in my toolbox, I also created an example. See attachment.
To make an advanced multi-purose tool from what I supplied, the "process" parameter would need enhancement.
Criticism welcome!
Attachments
aoo95416AutomaticTimeStampsAgain_0.ods
(12.85 KiB) Downloaded 182 times
Last edited by Lupp on Tue Oct 09, 2018 5:59 pm, edited 1 time in total.
On Windows 10: LibreOffice 24.2 (new numbering) and older versions, PortableOpenOffice 4.1.7 and older, StarOffice 5.2
---
Lupp from München
User avatar
Zizi64
Volunteer
Posts: 11359
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Macro code to add date/time when cell in row changed

Post by Zizi64 »

code contained in the example above has some flaws
Yes, it is true.
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.
showbi
Posts: 3
Joined: Mon Oct 08, 2018 4:06 pm

Re: Macro code to add date/time when cell in row changed

Post by showbi »

Thank you soo much Sir.... its worked for me...thanks alot.
LibreOffice Version: 5.1.6.2 on Ubuntu OS Version: :Linux 4.4
Post Reply