[Solved] Remarks on "[Tutorial] Favorite Recorded Calc Macros"

Let us know how we are doing -
Post Reply
cwolan
Posts: 151
Joined: Sun Feb 07, 2021 3:44 pm

[Solved] Remarks on "[Tutorial] Favorite Recorded Calc Macros"

Post by cwolan »

@MrProgrammer
A few remarks (not listed in order of importance) on your tutorial Favorite Recorded Calc Macros:

1.
Recording macros is much simpler then writing them. (...)
"then" seems inappropriate.

2.
• The first three macros are used to copy only part of a cell or cell range: the format, the formula, or the value. When using Styles, PasteFormat copies the style from one cell to a range. When an entire column has been copied to the clipboard, PasteFormat also copies its column width to the target column. PasteValues converts formulas to values. To record PasteUnformatted you must first place some text on the clipboard, so first copy something from a text document or a web page, not from Calc. This macro is useful for triggering the Text Import dialog.
PasteFormat appears twice, although PasteFormats was suggested earlier in the Tutorial.

3.
macro CopyText, steps to be recorded «F2» → Edit → Select All → Edit → Copy → «Escape»

When I record these steps, the resulting macro contains two inactive lines (with the framework commands).
Using the Escape key is not recorded.
MacroREC.JPG
MacroREC.JPG (58.3 KiB) Viewed 5033 times
Last edited by Hagar Delest on Fri Jun 21, 2024 7:15 am, edited 1 time in total.
Reason: tagged Solved.
OpenOffice 1.1.5 – 4.1.15
LibreOffice 3.3.0.4 – 24.8
Windows 7,10,11 64-bit
User avatar
MrProgrammer
Moderator
Posts: 5097
Joined: Fri Jun 04, 2010 7:57 pm
Location: Wisconsin, USA

Re: Remarks on "[Tutorial] Favorite Recorded Calc Macros"

Post by MrProgrammer »

cwolan wrote: Sat Jun 15, 2024 8:52 pm 1. "then" seems inappropriate.
Changed to: Recording macros is much simpler than writing them.

cwolan wrote: Sat Jun 15, 2024 8:52 pm 2. PasteFormat appears twice, although PasteFormats was suggested earlier in the Tutorial.
Changed to PasteFormats in both sentences.

cwolan wrote: Sat Jun 15, 2024 8:52 pm 3. When I record these steps, the resulting macro contains two inactive lines (with the framework commands).
I looked at the actual macro that I use, shown below. Perhaps I recorded it, realized it didn't do what I wanted, edited it, became accustomed to using it, and bound it to ⇧⌘C. I probably created it about ten years ago. From the name, its original purpose was to copy the text in a cell to the clipboard without the terminating newline. Earlier attempts to do that were more complicated, involving a MacOS service which I wrote to discard the last newline on the clipboard. So I needed to do Copy, run service, Paste.

Though not the original purpose, I realized the macro was also useful for copying the text of a formula to the clipboard. I use it with Safari so I can copy a formula from a cell and then paste its text (rather than its value) into a forum topic: select cell, ⇧⌘C. And I use with Calc it to copy a formula, without changing relative references, from one cell to another. This is easier than the technique in paragraph One can duplicate a formula … of [Tutorial] Formula Adjustments during Copy and Move. I use it more now for this secondary purpose and in my mind the macro is CopyText instead of NoNL.

Then later, perhaps after reading a topic in the forum, I thought this macro could be useful for others and I added it to the tutorial, forgetting that an edit was needed. I think I will just remove CopyText from the tutorial since it's purpose is to show what can be done without having to know how to write/edit macros.

Sub NoNL ' ⇧⌘C  Copy cell contents to clipboard without terminating NewLine
Rem             This macro also can be used to copy a cell's formula
Dim dispatch As Object : dispatch = createUnoService("com.sun.star.frame.DispatchHelper")
Dim document As Object : document = ThisComponent.CurrentController.Frame
dispatch.executeDispatch(document, ".uno:SetInputMode", "", 0, Array())
dispatch.executeDispatch(document, ".uno:SelectAll",    "", 0, Array())
dispatch.executeDispatch(document, ".uno:Copy",         "", 0, Array())
dispatch.executeDispatch(document, ".uno:Cancel",       "", 0, Array())
End Sub

Thank you for helping to improve the tutorial, cwolan.
Mr. Programmer
AOO 4.1.7 Build 9800, MacOS 13.7, iMac Intel.   The locale for any menus or Calc formulas in my posts is English (USA).
Post Reply