Page 1 of 1

[Solved] Macro to paste a specific character

Posted: Wed Mar 12, 2025 6:36 pm
by djwebb1969
I find the right and left hand curly quotes hard to find in Office Symbol. I want toolbar buttons to paste them. I've done the following, which doesn't work. I thought that if I put in ".uno:Paste", "", 0, Array()) it would work. What is the correct syntax?

Code: Select all

sub curlysingleleft
rem ----------------------------------------------------------------------
rem define variables
dim document   as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:Paste", "‘", 0, Array())


end sub

Re: Macro to paste a specific character

Posted: Wed Mar 12, 2025 7:06 pm
by MrProgrammer
djwebb1969 wrote: Wed Mar 12, 2025 6:36 pm What is the correct syntax?
You have an example of a macro which uses dispatcher services. This type of macro comes from using the Tools → Macros → Record feature. The syntax and semantics of dispatcher macros are not documented. You have two choices.

The simplest method is to record four macros which use Insert → Special Character. Recording simple macros to perform one action will take less than a minute. The characters you want are probably:
• U+2018 Left Single Quotation Mark
• U+2019 Right Single Quotation Mark
• U+201C Left Double Quotation Mark
• U+201D Right Double Quotation Mark
When you record macros, you don't need to learn about macro syntax because OpenOffice creates the macro for you. Do not attempt to understand or modify recorded macros. Just use what you're recorded.

You could also write your macros and not use the macro recording feature. The syntax for that is documented but learning how to write macros is difficult. Expect to spend at least a week to write your first macro, more if you're not already a programmer.
OpenOffice.org Macros Explained

Instead of using a macro, I recommend using the AutoText feature of Writer to insert characters in Writer. See Help → OpenOffice Help → Index → AutoText.

If this solved your problem please go to your first post use the Edit ✏️ button and add [Solved] to the start of the Subject field. Select the green checkmark icon at the same time.

Re: Macro to paste a specific character

Posted: Wed Mar 12, 2025 7:09 pm
by djwebb1969
Thank you ̇

Re: [Solved] Macro to paste a specific character

Posted: Wed Mar 12, 2025 10:26 pm
by Lupp
Though the thread is already marked SOLVED, I append this:

When using macros to support editing, the problem is often not in the writing (or probably recording) the macro, but in making it accessible in a suitable way.

Only under very special conditions the usage of macros for editing is recommendable.
Since I was somehow interested in the task, I wrote such a macro and a short explanation.

The attached example document is used as the macro container, and also customised with an additional toolbar for the access.

Of course, the macro doesn't exactly match the original topic. There is an older solution for this by the extension https://extensions.openoffice.org/de/pr ... characters and LibreOffice has an additional means (the Alt+X feature).

The assumed subject for my solution would be:
"How to put text ranges in brackets with the help of a macro?"
app112591_bracketing.odt
(44.37 KiB) Downloaded 33 times

Re: [Solved] Macro to paste a specific character

Posted: Thu Mar 13, 2025 4:52 am
by djwebb1969
Thank you for that. Very useful.

Re: [Solved] Macro to paste a specific character

Posted: Thu Mar 13, 2025 12:34 pm
by Lupp
Off topic (no macros), but related:
editHelpersInHeaderAnchoredFrame.ott
(29.79 KiB) Downloaded 63 times

Re: [Solved] Macro to paste a specific character

Posted: Fri Mar 14, 2025 5:21 pm
by JeJe

Code: Select all

Sub Addquotes
dim vc
on error resume next
vc = thiscomponent.currentcontroller.viewcursor
vc.string = "‘" & vc.string & "’"
End Sub
You can use find/replace without a macro if what you want to surround with quotes is all in one paragraph

fandr.jpg
fandr.jpg (23.69 KiB) Viewed 2770 times