[Solved] Problem editing a macro

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
RW9275
Posts: 10
Joined: Fri Jan 11, 2019 4:55 am

[Solved] Problem editing a macro

Post by RW9275 »

OpenOffice ClearContents Macro.txt
(1.2 KiB) Downloaded 134 times
I know there is probably a simple answer to this, but here goes: I recorded a macro to Clear Content on a spreadsheet. I recorded B2:H14. This works fine, but when I try to add cell B18, it only deletes cell B18. I will appreciate any help. Please see the attachment.
Last edited by Hagar Delest on Fri Jan 11, 2019 9:32 am, edited 1 time in total.
Reason: tagged solved
OpenOffice 4.1.5
Windows 10 Home 64Bit
FJCC
Moderator
Posts: 9278
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: Problem editing a macro

Post by FJCC »

Try this

Code: Select all

sub ClearContents
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 = "ToPoint"
args1(0).Value = "$B$2:$H$14"
dispatcher.executeDispatch(document, ".uno:GoToCell", "", 0, args1())

rem ----------------------------------------------------------------------
dim args2(0) as new com.sun.star.beans.PropertyValue
args2(0).Name = "Flags"
args2(0).Value = "SVDFN"

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

args1(0).Name = "ToPoint"
args1(0).Value = "$B$18"
dispatcher.executeDispatch(document, ".uno:GoToCell", "", 0, args1())

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


rem ----------------------------------------------------------------------
dim args3(0) as new com.sun.star.beans.PropertyValue
args3(0).Name = "ToPoint"
args3(0).Value = "$B$2"

dispatcher.executeDispatch(document, ".uno:GoToCell", "", 0, args3())


end sub
The idea is to select the cells with a ToPoint, delete the contents and THEN go to the next location with a second ToPoint and delete there.
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
RW9275
Posts: 10
Joined: Fri Jan 11, 2019 4:55 am

Re: Problem editing a macro

Post by RW9275 »

Perfect. Thanks!
OpenOffice 4.1.5
Windows 10 Home 64Bit
Post Reply