Using a macro to unassign macro's?

Hi,

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
vnd.sun.star.script:Standard.Module1.X?language=Basic&location=application.


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 close merge delete

Sort by » oldest newest most voted

Hallo

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
next
End Sub


#python
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)


Karolus

more

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

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

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

BASIC runtime error. Object variable not set


Any idea what could be causing this error?

more