Insert current date

Years ago in Word Perfect there was a feature that allowed me to use a
shortcut key (even picking from a menu would be good) that inserted today's
date. Does Libre Writer have this feature?

I've never written a macro and the couple of instructions I've seen look
complicated. If there is no feature for this, would their be a way to write
a macro for the tecnically challenged?

Peggy

Years ago in Word Perfect there was a feature that allowed me to use a
shortcut key (even picking from a menu would be good) that inserted today's
date. Does Libre Writer have this feature?

Insert → Field → More fields → Document: under Type select Date and then if
its fixed or should update any time you open the document. On the right
column you can choose from different formats.

Regards,
Ricardo

And if you use this functionality often, you can create an autotext with the field and its formatting.

Best regards.
JBF

Sorry for the untrimmed quote and top post Gmail client forces it like
this.

I started to write a macro (and failed miserably) because I wanted to, in a
spreadsheet, enter today's date and time in a column (or two) that then
*never* updates again. All of my attempts at getting this to work (via
existing methods or by creating a macro) failed.

I simply had to accept that I had to enter it every time I I made an entry.

If I got it wrong l'd love to hear of a better way to do it.

It's a while since I used this.

https://help.libreoffice.org/Common/Recording_a_Macro

From memory you record the macro into your template and all subsequent docs should inherit the macro.

HTH

Tim

Hello Peggy,

Years ago in Word Perfect there was a feature that allowed me to use a
shortcut key (even picking from a menu would be good) that inserted today's
date. Does Libre Writer have this feature?

I've never written a macro and the couple of instructions I've seen look
complicated. If there is no feature for this, would their be a way to write
a macro for the tecnically challenged?

While in Calc there's no need for a macro (the Ctrl + ; (semicolon) shortcut will do :wink: such is not the case in Writer, yet.

So, yes, you need to create a macro then connect a keyboard shortcut to it. The process is quite simple if you use the macro recorder.

Here's how (longer to write than to execute) :

1. Creating the macro using the macro recorder

Note: the macro recorder is not available until you've activated the corresponding option in Tools > Options > LibreOffice > Options, Enable macro recording.

a. Open an empty Writer document

b. Goto Tools > Macro > Record macro
(a macro recorder toolbar is displayed: you'll press the "Stop recording" button when you're done)

c. Hit Ctrl+F2 to call the Insert Fields dialog,

d. in the Document thumbnail select:

Type = Date
Select = Date
Format = select the wanted format

e. Clic Insert, then Close

f. Clic the "Stop recording" button

g. A dialog opens that allows you to save the macro code.
Enter a name for your macro in Macro Name
Save macro in : select MyMacros > Standard > Module1
Click Save

(a sample of the macro code is given below)

2. Connecting the macro execution with a keyboard shortcut

a. Tools > Customize, Keyboard thumbnail

Shortcut Keys = choose an appropriate shortcut (Ctrl + ; might do...)
Category = LibreOffice Macros -> MyMacros -> Standard -> Module1
Function = select the macro created at step 1 above

b. Check the "Writer" radio button (the shortcut will be available in Writer only), then Modify which makes the shortcut appear in the Keys panel.

c. Validate OK

From now on, pressing Ctrl + ; in Writer inserts the current date.

8< -------------------------------------------------------------------
sub InsertCurrentDate

dim document as object
dim dispatcher as object

rem get access to the document
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

dim args1(5) as new com.sun.star.beans.PropertyValue
args1(0).Name = "Type"
args1(0).Value = 0
args1(1).Name = "SubType"
args1(1).Value = 1
args1(2).Name = "Name"
args1(2).Value = ""
args1(3).Name = "Content"
args1(3).Value = "0"
args1(4).Name = "Format"
args1(4).Value = 10036 '
args1(5).Name = "Separator"
args1(5).Value = " "

dispatcher.executeDispatch(document, ".uno:InsertField", "", 0, args1())

end sub
-------------------------------------------------------------------- >8

HTH,

This is simply untrue, of course. There is plenty of help out there on the web to show you how to do whatever you need. Please don't blame your tools or encourage others to copy your example.

Brian Barker

While in Calc there's no need for a macro (the Ctrl + ; (semicolon)
shortcut will do :wink: such is not the case in Writer, yet.

So, yes, you need to create a macro then connect a keyboard shortcut to
it. The process is quite simple if you use the macro recorder.

Here's how (longer to write than to execute) :

1. Creating the macro using the macro recorder

Note: the macro recorder is not available until you've activated the
corresponding option in Tools > Options > LibreOffice > Options, Enable
macro recording.

This will be (in some versions ?) Tools > Options > LibreOffice >
Advanced, Enable macro recording.

Hi Peggy,

there is no macro needed.

Open a Writer-document
Go to
Tools > Customize > Keyboard
Type in "Functions": 'Date'
Now look for a free Shortcut-Key, for example Ctrl+7.
Click "Modify" on the right.
Click "Save".

Now you could insert the current date with Ctrl+7.

Regards

Robert

Hello Robert,

there is no macro needed.

Open a Writer-document
Go to
Tools > Customize > Keyboard
Type in "Functions": 'Date'
Now look for a free Shortcut-Key, for example Ctrl+7.
Click "Modify" on the right.
Click "Save".

Now you could insert the current date with Ctrl+7.

OMG! How did I overlook that?

Many thanks Robert!

All the best,

Hi Philip,

Note: the macro recorder is not available until you've activated the
corresponding option in Tools > Options > LibreOffice > Options, Enable
macro recording.

This will be (in some versions ?) Tools > Options > LibreOffice >
Advanced, Enable macro recording.

Ahem. Yes, I stand corrected /o\

Anyway, Robert's solution is much faster!

Best regards,

Thanks Robert, that's very helpful.

Now, how would I change the result to YYYY-MM-DD?

Regards,

Howard

Hi Howard,

Now, how would I change the result to YYYY-MM-DD?

Dubbelclick on the date. You get the dialog for changing the format.

I don't know how to change the standard - except to change the language
of the text to, for example, Englisch(Canadian).

Regards

Robert

Thanks Robert, that's very helpful.

Now, how would I change the result to YYYY-MM-DD?

Regards,

Howard

This is a little more difficult, but not by much.

Right click the date.
     Select Additional formats in the Format column.
     Enter what you want in the Format Code box.
     Click OK.

If you then want to convert this to AutoText after changing the date format,
         Ctl+F3 opens AutoText dialog
         Type the name of it in the Name box.
          Modify the Shortcut name if desired.
          Click the AutoText button and select New(text only) from the list.
          Click closed.

Why not use the default of <CTRL>+<;> (that's a semicolon)? The format
is dependent on Locale Setting.

Add the <SHIFT> to insert current time.

Thanks Robert, that's very helpful.

Now, how would I change the result to YYYY-MM-DD?

Regards,

Howard

This is a little more difficult, but not by much.

Right click the date.
     Select Additional formats in the Format column.
     Enter what you want in the Format Code box.
     Click OK.

If you then want to convert this to AutoText after changing the date format,
         Ctl+F3 opens AutoText dialog
         Type the name of it in the Name box.
          Modify the Shortcut name if desired.
          Click the AutoText button and select New(text only) from the list.
          Click closed.

Dan

OK, I left out one important point:

After right clicking the date created by Ctrl+7, select Fields from the menu.
               Then select Additional formats in the Format column...

Dan

Hi T.R.,

Why not use the default of <CTRL>+<;> (that's a semicolon)?

Add the <SHIFT> to insert current time.

This is the default for Calc. There isn't any default for date ore time
in Writer. But the combination is free for using in Writer also. So you
could take this combination if you want and haven't used it for other
functionality.

Regards

Robert