Date: prev next · Thread: first prev next last
2018 Archives by date, by thread · List index


On 21/05/18 12:03, Jean-Francois Nifenecker wrote:
While in Calc there's no need for a macro (the Ctrl + ; (semicolon)
shortcut will do ;) 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.


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

-- 
To unsubscribe e-mail to: users+unsubscribe@global.libreoffice.org
Problems? https://www.libreoffice.org/get-help/mailing-lists/how-to-unsubscribe/
Posting guidelines + more: https://wiki.documentfoundation.org/Netiquette
List archive: https://listarchives.libreoffice.org/global/users/
All messages sent to this list will be publicly archived and cannot be deleted

Context


Privacy Policy | Impressum (Legal Info) | Copyright information: Unless otherwise specified, all text and images on this website are licensed under the Creative Commons Attribution-Share Alike 3.0 License. This does not include the source code of LibreOffice, which is licensed under the Mozilla Public License (MPLv2). "LibreOffice" and "The Document Foundation" are registered trademarks of their corresponding registered owners or are in actual use as trademarks in one or more countries. Their respective logos and icons are also subject to international copyright laws. Use thereof is explained in our trademark policy.