[Solved] Problem editing a macro

Creating a macro - Writing a Script - Using the API

[Solved] Problem editing a macro

Postby RW9275 » Fri Jan 11, 2019 5:10 am

OpenOffice ClearContents Macro.txt
(1.2 KiB) Downloaded 36 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
RW9275
 
Posts: 10
Joined: Fri Jan 11, 2019 4:55 am

Re: Problem editing a macro

Postby FJCC » Fri Jan 11, 2019 6:38 am

Try this
Code: Select all   Expand viewCollapse view
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.
Windows 10 and Linux Mint, since 2017
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
FJCC
Moderator
 
Posts: 7751
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: Problem editing a macro

Postby RW9275 » Fri Jan 11, 2019 6:46 am

Perfect. Thanks!
OpenOffice 4.1.5
Windows 10 Home 64Bit
RW9275
 
Posts: 10
Joined: Fri Jan 11, 2019 4:55 am


Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 2 guests