Set First/lastname and Initials to Writer using macros

Creating a macro - Writing a Script - Using the API

Set First/lastname and Initials to Writer using macros

Postby mamkiks » Mon Mar 26, 2018 1:58 pm

I need to change First Name and Lastname of User data using macros to display who make changes in document

I've used getDocumentProperties().Author
but when I move to
Tools>> Option >> userdata
the first and last name doesn't change
and records added or deleted from document the Author still the same person
Last edited by RoryOF on Mon Mar 26, 2018 2:02 pm, edited 1 time in total.
Reason: Fixed typo in subject [RoryOF, Moderator]
OpenOffice 4.1.5 on Windows 10
mamkiks
 
Posts: 17
Joined: Sun Mar 25, 2018 1:00 pm

Re: Set First/lastname and Initials to Writer using macros

Postby John_Ha » Mon Mar 26, 2018 2:54 pm

mamkiks wrote:I need to change First Name and Lastname of User data using macros to display who make changes in document

Welcome to the (wrong) forum. There is a macros forum at Macros and UNO API

Edit > Changes > Record ..., records changes by author - you probably need to ensure authors have their name in User Data.

What precisely are you trying to do that needs you to go into a .odt file and change the author? Isn't there a better way? I ask because this may be a classic XY problem. You want to do X but you cannot. You come up with a solution Y which you find does not quite work and is probably not a good idea. You then ask for help to fix Y.

It is far better to say "I want to do X ..." and ask for help on X. That way we can consider all your options without getting drawn down the possible dead end of Y - see The XY problem.

As a new poster you will find much useful information in the Writer FAQ, the Writer Tutorials, the up to date Writer guide and the Writer Manual. May I suggest you bookmark the pages.

Press F1 to access the Help screen and search for your problem

The chapter headings in the manual are:

1 - Introducing Writer
2 - Setting up Writer
3 - Working with Text
4 - Formatting Pages
5 - Printing, Exporting, Faxing and E-Mailing
6 - Introduction to Styles
7 - Working with Styles
8 - Working with Graphics
9 - Working with Tables
10 - Working with Templates
11 - Using Mail Merge
12 - Tables of Contents, Indexes and Bibliographies
13 - Working with Master Documents
14 - Working with Fields
15 - Using Forms in Writer
16 - Customizing Writer – Keyboard shortcuts.

When a pop-up window opens, click the Help button for extensive help on that function - it is often more comprehensive than the manual.
Last edited by John_Ha on Mon May 21, 2018 12:26 pm, edited 1 time in total.
AOO 4.1.6, Windows 7 Home 64 bit

See the Writer Manual, the Writer FAQ, the Writer Tutorials and the Writer guide.

Remember: Always save your Writer files as .odt files. - see here for the many reasons why.
John_Ha
Volunteer
 
Posts: 6575
Joined: Fri Sep 18, 2009 5:51 pm
Location: UK

Re: Set First/lastname and Initials to Writer using macros

Postby mamkiks » Mon Mar 26, 2018 3:11 pm

Sorry for posting in wrong forum

My problem that I have documents in local device and there are more than one person review and making changes on it
I need to show inputBox that ask the user to enter his name then changes created will be assigned with his name in records
so I need to edit username with inputBox using macros without needing to go to tools >> options >> userData

also I wanna ask, could I create a table with users details so when user try to open document, the inputBox asks him to enter your name then search in the table if this name exists or not then set the First and last name with data entered in inputBox
OpenOffice 4.1.5 on Windows 10
mamkiks
 
Posts: 17
Joined: Sun Mar 25, 2018 1:00 pm

Re: Set First/lastname and Initials to Writer using macros

Postby John_Ha » Mon Mar 26, 2018 4:38 pm

Sorry, that is still not clear.

Say the file contains "The black dog". If User_A edits it to "The black cat", and User_B later edits it to "The white cat", what do you want to save?

Or does anyone who saves a file take full responsibility for the entire file, and not just for the edits (s)he made?

Have a look at fields in Chapter 14 and Assigning macros to events in Chapter 16.

Can you use Edit > Changes > Record - that is what it is there for! See Tracking changes to a document in Chapter 3.
AOO 4.1.6, Windows 7 Home 64 bit

See the Writer Manual, the Writer FAQ, the Writer Tutorials and the Writer guide.

Remember: Always save your Writer files as .odt files. - see here for the many reasons why.
John_Ha
Volunteer
 
Posts: 6575
Joined: Fri Sep 18, 2009 5:51 pm
Location: UK

Re: Set First/lastname and Initials to Writer using macros

Postby RoryOF » Mon Mar 26, 2018 4:47 pm

I think Edit > Changes > Record will do mist of what this user wants. Certainly simpler than going down the macro road!
Apache OpenOffice 4.1.6 on Xubuntu 18.04.2 (mostly 64 bit version) and very infrequently on Win2K/XP
User avatar
RoryOF
Moderator
 
Posts: 28565
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Set First/lastname and Initials to Writer using macros

Postby mamkiks » Tue Mar 27, 2018 9:13 am

When I use Edit > Changes > Record it show changes and who made this changes

There are many users can review and edit this file on the same local machine

I need the records save who make changes from these users

for example My Name is Mohammed

I wrote "I love cats"
in the records it shows that >> insertion "I love cats" by Mohammed

then John open this document and delete cats then the document now contains "I love"

in the records it shows that >> insertion "I love cats" by Mohammed
. >> Deletion "cats" by john

and so on
OpenOffice 4.1.5 on Windows 10
mamkiks
 
Posts: 17
Joined: Sun Mar 25, 2018 1:00 pm

Re: Set First/lastname and Initials to Writer using macros

Postby RoryOF » Tue Mar 27, 2018 10:28 am

I think that satisfies your main need. Extracting a list of users who edited the file would need a custom macro (I have not investigated this); be aware that heavy use of the mechanism for recording changes can lead to the file becoming cumbersome and tangled, perhaps even to the point of instability.
Apache OpenOffice 4.1.6 on Xubuntu 18.04.2 (mostly 64 bit version) and very infrequently on Win2K/XP
User avatar
RoryOF
Moderator
 
Posts: 28565
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Set First/lastname and Initials to Writer using macros

Postby mamkiks » Tue Mar 27, 2018 10:58 am

mmmmmmmmm, I just need in the beginning to show macro inputBox with title Enter your name >> when inserting "John" and making changes
the changes in records show that the maker is "John"
is there a possible way to achieve this ?
OpenOffice 4.1.5 on Windows 10
mamkiks
 
Posts: 17
Joined: Sun Mar 25, 2018 1:00 pm

Re: Set First/lastname and Initials to Writer using macros

Postby keme » Tue Mar 27, 2018 11:00 am

mamkiks wrote:When I use Edit > Changes > Record it show changes and who made this changes

There are many users can review and edit this file on the same local machine

I need the records save who make changes from these users

for example My Name is Mohammed

I wrote "I love cats"
in the records it shows that >> insertion "I love cats" by Mohammed

then John open this document and delete cats then the document now contains "I love"

in the records it shows that >> insertion "I love cats" by Mohammed
. >> Deletion "cats" by john

and so on

Yes, this is how it should work when using "Record changes", assuming that each user logs in to the computer with their personal credentials. Is your problem now solved, or do you want to distinguish between editor while using the same computer user account?

Your post appears to be a description of what you have now. Is it instead a description of how you want it to be? The simplest solution for this is to save your file in a folder shared by all the users, use a personal login to the computer and enter user credentials registered in the Office suite.
User avatar
keme
Volunteer
 
Posts: 3103
Joined: Wed Nov 28, 2007 10:27 am
Location: Egersund, Norway

Re: Set First/lastname and Initials to Writer using macros

Postby mamkiks » Tue Mar 27, 2018 11:14 am

Iwant to distinguish between editor while using the same computer

when I use Tools >> Options >> user data it shows to me firstname, lastname and Initials
Is there a way to change these fields using macros ? by entering the name and initials in inputbox without moving to Tools >> Options >> user data to change it
OpenOffice 4.1.5 on Windows 10
mamkiks
 
Posts: 17
Joined: Sun Mar 25, 2018 1:00 pm

Re: Set First/lastname and Initials to Writer using macros

Postby RoryOF » Tue Mar 27, 2018 11:36 am

mamkiks wrote:Iwant to distinguish between editor while using the same computer

when I use Tools >> Options >> user data it shows to me firstname, lastname and Initials
Is there a way to change these fields using macros ? by entering the name and initials in inputbox without moving to Tools >> Options >> user data to change it


Doing that is pointless, as it changes the main author of the document. It is simpler if each User is caused to log in to the computer (and hence to OpenOffice) using their own account.
Apache OpenOffice 4.1.6 on Xubuntu 18.04.2 (mostly 64 bit version) and very infrequently on Win2K/XP
User avatar
RoryOF
Moderator
 
Posts: 28565
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Set First/lastname and Initials to Writer using macros

Postby John_Ha » Tue Mar 27, 2018 12:15 pm

So, If I restate your problem it is:

1 I have several people who use the same PC.
2 Each user edits the document.
3 I want to record the user's name when he edits the file.

Solution 1:

Set up usernames for each user on the PC so each logs on as a separate user. Install AOO so each user can use it. Each user fills in their username in AOO.

Now, when each user edits the file using Record changes their name is recorded.

 Edit: A thought. You could write a macro which processed the saved .odt file and applied all the changes and recorded the name of the person who made them. You could even append the author and the changes made to a Change log held at the bottom of the document. 


Solution 2:

Write a macro to ask for the user's name
Run the macro when the document opens - see Tools > Customise > Events
The macro fills in a field with the user's name.

Note that this method only stores the name of the last user to edit the document. It is why I asked "does anyone who saves a file take full responsibility for the entire file, and not just for the edits (s)he made?".

The macro could add the user name, date and time to a list of names which would then record all users who had edited the file. Search the Macros forum for ideas writing the macro and see Andrew Pitonyak's OpenOffice Macro Information
Last edited by John_Ha on Tue Mar 27, 2018 2:29 pm, edited 1 time in total.
AOO 4.1.6, Windows 7 Home 64 bit

See the Writer Manual, the Writer FAQ, the Writer Tutorials and the Writer guide.

Remember: Always save your Writer files as .odt files. - see here for the many reasons why.
John_Ha
Volunteer
 
Posts: 6575
Joined: Fri Sep 18, 2009 5:51 pm
Location: UK

Re: Set First/lastname and Initials to Writer using macros

Postby keme » Tue Mar 27, 2018 1:47 pm

RoryOF wrote:
mamkiks wrote:Iwant to distinguish between editor while using the same computer

when I use Tools >> Options >> user data it shows to me firstname, lastname and Initials
[...]


Doing that is pointless, as it changes the main author of the document. [...]

No, it doesn't. It changes "last edited by", but the "Created by" property remains unchanged. Also, the current user data is saved with each change recorded. You can change user data multiple times in one edit (useful e.g. if you receive suggestions from people though channels other than direct editing, and want to insert them as recorded edits on behalf of those people).
User avatar
keme
Volunteer
 
Posts: 3103
Joined: Wed Nov 28, 2007 10:27 am
Location: Egersund, Norway

Re: Set First/lastname and Initials to Writer using macros

Postby Zizi64 » Tue Mar 27, 2018 1:48 pm

I need to change First Name and Lastname of User data using macros to display who make changes in document

I've used getDocumentProperties().Author
but when I move to
Tools>> Option >> userdata
the first and last name doesn't change
and records added or deleted from document the Author still the same person


The author of a document and the user of the office suite are two different data, but they are same in some cases.
They are same, when YOU create a new empty document based on the default template: the user name will be copied into the document author field - when the office suite creates the new document.

Therefore you must change both of the fields in an existing document (if you really want to change the user name of the office suite, AND the author of the document).
Tibor Kovacs, Hungary; LO4.4.7, LO6.1.5 on Win7-10 x64Prof.
PortableApps, winPenPack: LO3.3.0-6.2.2; AOO4.1.5
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: 7827
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Set First/lastname and Initials to Writer using macros

Postby RoryOF » Tue Mar 27, 2018 2:36 pm

keme wrote:
RoryOF wrote:
mamkiks wrote:Iwant to distinguish between editor while using the same computer

when I use Tools >> Options >> user data it shows to me firstname, lastname and Initials
[...]


Doing that is pointless, as it changes the main author of the document. [...]

No, it doesn't. It changes "last edited by", but the "Created by" property remains unchanged.
.


Thanks for clarification, Keme. I am fortunate that I only edit my own documents, so have no problem with multiple users.
Apache OpenOffice 4.1.6 on Xubuntu 18.04.2 (mostly 64 bit version) and very infrequently on Win2K/XP
User avatar
RoryOF
Moderator
 
Posts: 28565
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Set First/lastname and Initials to Writer using macros

Postby mamkiks » Tue Mar 27, 2018 3:16 pm

So there is no way to set user data using macros?

I need to Integrate openOffice with alfresco
then each user access document check if he has the authority to access this document or not before using it
then i want to set his data as user data to ensure it is not fake name after authentication

Could you understand what I need or still not clear.
OpenOffice 4.1.5 on Windows 10
mamkiks
 
Posts: 17
Joined: Sun Mar 25, 2018 1:00 pm

Re: Set First/lastname and Initials to Writer using macros

Postby John_Ha » Tue Mar 27, 2018 3:42 pm

mamkiks wrote:So there is no way to set user data using macros?

Yes. See the post here

I think that what you are attempting to do seems very ambitious if you want to design something that is foolproof and establishes a (legally? auditable?) reliable record of changes, especially as you seem to be asking basic questions here suggesting you might not fully understand the consequences of doing something.

You did not answer my question suggesting you do not seem to appreciate the difference between keeping a log of each change and who made it; and keeping a log of the last person who made a change. You need to answer that question first.

If you persist in trying to do it, it would be very sensible to write a formal specification document for what you want to do, which covers each eventuality, before you start coding.

I would be tempted to use a purchased database, and have each document as a record in the database. Users logon to the database to make changes, and the database log records every change made to each record, who made it and when. The database also prevents two users making changes at the same time.
AOO 4.1.6, Windows 7 Home 64 bit

See the Writer Manual, the Writer FAQ, the Writer Tutorials and the Writer guide.

Remember: Always save your Writer files as .odt files. - see here for the many reasons why.
John_Ha
Volunteer
 
Posts: 6575
Joined: Fri Sep 18, 2009 5:51 pm
Location: UK

Re: Set First/lastname and Initials to Writer using macros

Postby John_Ha » Tue Mar 27, 2018 6:49 pm

I forgot to say that, in my experience, any method which relies on the user doing something, and which the user cannot prevent running or cannot jump out of, is doomed to failure.

Users seem to be incapable of following instructions no matter how simple or how rigorously enforced they are.
AOO 4.1.6, Windows 7 Home 64 bit

See the Writer Manual, the Writer FAQ, the Writer Tutorials and the Writer guide.

Remember: Always save your Writer files as .odt files. - see here for the many reasons why.
John_Ha
Volunteer
 
Posts: 6575
Joined: Fri Sep 18, 2009 5:51 pm
Location: UK

Re: Set First/lastname and Initials to Writer using macros

Postby mamkiks » Wed Mar 28, 2018 10:00 am

keeping a log of each change and who made it

for example In microsoft office word i'm using this macro to set username
Application.UserName= inputBox("Please Enter your name","Dear User");
Application.UserInitials= inputBox("Please Enter your Initials","Dear User");

I need to run this code but in open office instead of Microsoft office
OpenOffice 4.1.5 on Windows 10
mamkiks
 
Posts: 17
Joined: Sun Mar 25, 2018 1:00 pm


Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 2 guests