Ask Your Question

Using a macro to unassign macro's? [closed]

asked 2015-03-23 01:38:02 +0200

LibreGuy gravatar image


I have a macro (let's call it X) assigned to 2 events ("Save Document" and "Save Document As").This macro does some useful things to my document. However, I did some testing and found out that if macro X is not available in LibreOffice, an error message will show up:

A Scripting Framework error occurred while running the Basic script

Actually, this behavior is quite understandable. The assigned macro is not available which results in an error message. Now the problem is that when I send my document with the assigned macro in it to someone else, he or she will see this exact same error message. Again, understandable because he or she does not have my custom made macro available on their computer.

So what I was wondering is if it it possible to create a macro (and if so how) that clears all macro's that are assigned to a document. If so, I could run this macro before sending the document to someone else. So, for example, if I first assigned 10 macro's to 10 events, they would all be unassigned after I ran that one specific macro. Can it be done?

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by Alex Kemp
close date 2020-08-17 22:54:21.674474

2 Answers

Sort by » oldest newest most voted

answered 2015-03-23 06:51:46 +0200

karolus gravatar image

updated 2015-03-23 07:33:26 +0200


See second Answer posted by OP It seems you have to loop through every event which is asigned to some macro

rem 'basic'
Sub remove_doc_events
    doc = thisComponent
    events = doc.Events
    For each eventname in events.ElementNames
        Event = events.getByName( eventname )
        if Event then
            Event(1).Value = ""
            events.replaceByName(eventname, Event)
        End If
End Sub

def remove_doc_events():
    doc = XSCRIPTCONTEXT.getDocument()
    events = doc.Events
    for eventname in events.ElementNames:
        Event = events.getByName( eventname )
        if Event:
            Event[1].Value = ''
            events.replaceByName(eventname, Event)


edit flag offensive delete link more


Many thanks Karolus! I will give that a try!!!

LibreGuy gravatar imageLibreGuy ( 2015-03-23 09:46:17 +0200 )edit

answered 2015-03-23 23:48:18 +0200

LibreGuy gravatar image

The line "if Event then" is causing an error:

BASIC runtime error. Object variable not set

Any idea what could be causing this error?

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2015-03-23 01:38:02 +0200

Seen: 284 times

Last updated: Mar 23 '15