Bug 122980 - Calc: Macro does not execute as recorded if selection is done with mouse
Summary: Calc: Macro does not execute as recorded if selection is done with mouse
Status: RESOLVED NOTABUG
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Calc (show other bugs)
Version:
(earliest affected)
6.1.4.2 release
Hardware: All All
: medium normal
Assignee: Not Assigned
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: Macro-Recording
  Show dependency treegraph
 
Reported: 2019-01-25 19:53 UTC by roger.millichamp
Modified: 2022-03-18 15:31 UTC (History)
2 users (show)

See Also:
Crash report or crash signature:
Regression By:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description roger.millichamp 2019-01-25 19:53:27 UTC
Description:
I am trying to create a macro that deletes the contents all rows in a column except 1. When I record the macro the steps I take have the desired effect. When I run the macro no cells have their contents deleted.

Steps to Reproduce:
We are going to create and run a macro that deletes all rows in Column A except row 1
1.	Create the spreadsheet
  a.	  Put a value in rows 1 and 2 of Column A
2.	Record the macro
  a.	  Select the menu item: Tools -> Macros -> Record Macro
  b.	  Select the whole of Column A by selecting the column label
  c.	  Deselect cell A1 by Control+Left Mouse Click in the cell
  d.	  Select the menu item: Sheet -> Clear Cells. This opens the Delete Content dialogue
  e.	  In the dialogue select OK. The contents of cell A2 are deleted but cell A1 remains unchanged. 
          This the required behaviour.
  f.	  Stop recording the macro
  g.	  Save the macro as desired.
3.	Restore the Spreadsheet, put the deleted value back
  a.	  Put a value in cell A2
4.	Execute the macro
  a.	  Select the menu item Tools ->Macros -> Run Macro… which opens the Macro Selector dialogue
  b.	  In the dialogue
     i.	    Select the macro saved in step 2g above
    ii.	    Select the Run button
  c.	  The contents of cell A2 are not deleted which is not what was recorded
5.	View the macro code. 
  a.	  Select the menu item Tools -> Edit Macros
  b.	  Select the Macro stored in step 2g above
  c.	  The code is in the Additional Information field below.


Actual Results:
The contents of cell A2 are not deleted

Expected Results:
The contents of cell A2 should be deleted because that is what the recorded steps did.


Reproducible: Always


User Profile Reset: No



Additional Info:
The code of the macro is as follows

sub testdelete
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 ----------------------------------------------------------------------
dim args1(0) as new com.sun.star.beans.PropertyValue
args1(0).Name = "Flags"
args1(0).Value = "SVDFN"

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

end sub

Help Info
Version: 6.1.4.2 (x64)
Build ID: 9d0f32d1f0b509096fd65e0d4bec26ddd1938fd3
CPU threads: 4; OS: Windows 10.0; UI render: default; 
Locale: en-GB (en_GB); Calc: CL
Comment 1 Oliver Brinzing 2019-01-26 14:45:04 UTC
reproducible with

Version: 6.1.5.1 (x64)
Build-ID: f18954c1ba9116b85c32b6bdbc0188d3e0fd24c7
CPU-Threads: 4; BS: Windows 10.0; UI-Render: Standard; 
Gebietsschema: de-DE (de_DE); Calc:

macro recording does not save cell selections.

btw: a better solution would be to use LO API, e.g.:

Sub DeleteRange()
	Dim oDoc as Object
	Dim oSheet as Object
	Dim oRange as Object
	Dim nFlag as Long
	
	oDoc = ThisComponent
	oSheet = oDoc.getSheets().getByName("Sheet1")
	oRange = oSheet.getCellRangeByName("A2:A10")
	
	' https://www.openoffice.org/api/docs/common/ref/com/sun/star/sheet/CellFlags.html
	nFlag = com.sun.star.sheet.CellFlags.VALUE +_
		com.sun.star.sheet.CellFlags.STRING +_
		com.sun.star.sheet.CellFlags.DATETIME

	oRange.clearContents(nFlag)
End Sub
Comment 2 QA Administrators 2021-01-26 05:12:36 UTC Comment hidden (obsolete)
Comment 3 Timur 2022-03-18 15:20:57 UTC
I guess that this can be NotABug per documentation.
Because https://help.libreoffice.org/latest/en-US/text/shared/guide/macro_recording.html?DbPAR=SHARED explains Limitations of the macro recorder, including that selection cannot be made with mouse. 

Of course that's not satisfying, but we cannot ask a chnage there, because it was already explained that such changes are not possible unless macro recorder is completely rewritten. 

What you can do is record all with keyboard, starting from the 1st selection Edit-Select-Column etc.