Ask Your Question
0

Using a macro to unassign macro's?

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

LibreGuy gravatar image

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

2 Answers

Sort by » oldest newest most voted
0

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

karolus gravatar image

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

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

edit flag offensive delete link more

Comments

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

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

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
Login/Signup to Answer

Question Tools

1 follower

Stats

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

Seen: 214 times

Last updated: Mar 23 '15