简体   繁体   中英

Libre Office, Clearing a Range

I have been looking online to get the idea how to acess a range and then "clearing" it. Sadly even though i have found several solutions, vba in libre office makes things really complicated to understand. I have tried to record a macro, and edit it... It works but not as i want it to. I need to execute the below code from a Form (Dialog) and it does what its meant to, but shows everything in the background and I can't have that .... is there a way, to do this ? for example in vba Exel I would just write :

Range("A1:DA25000").ClearContents (or .Delete)

Here is what I got with macro recordings:

Function Brisanje()

dim document   as object
dim dispatcher as object

document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

dim args1(0) as new com.sun.star.beans.PropertyValue
args1(0).Name = "Nr"
args1(0).Value = 2

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

dim args2(0) as new com.sun.star.beans.PropertyValue
args2(0).Name = "ToPoint"
args2(0).Value = "$A$1:$DA$25000"

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

dispatcher.executeDispatch(document, ".uno:ClearContents", "", 0, Array())

end Function

The code you are looking for is in Andrew Pitonyak's macro document , section 6.4. Clear a cell 6.4. Clear a cell . Notice that the code works for multiple cells as well:

REM You can use a range such as "A1:B2"

Macro recordings are not a good way to learn how to write macros. They generate dispatcher code, which is different from working with the UNO API.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM