Deleting MACRO from DOC/DOCX/ODT File

Java, C++, C#, Delphi... - Using the UNO bridges
Post Reply
sachin.shinde
Posts: 4
Joined: Fri Jul 21, 2017 2:02 pm

Deleting MACRO from DOC/DOCX/ODT File

Post by sachin.shinde »

Hi All,

I am trying to Deleting MACRO from DOC/DOCX/ODT File using Open office SDK 4.1.3 using C# library, I not able to find any guidance,
can you please provide any pointers regarding.

Thanks,
Sachin S
OpenOffice 4.1.3 Windows 10
User avatar
RoryOF
Moderator
Posts: 34586
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Deleting MACRO from DOC/DOCX/ODT File

Post by RoryOF »

/Tools/ Options/ Organise Macros, select the language in which the macro was written (try all in turn if not certain), select the macros and press the Delete button on the macro organise window.
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
sachin.shinde
Posts: 4
Joined: Fri Jul 21, 2017 2:02 pm

Re: Deleting MACRO from DOC/DOCX/ODT File

Post by sachin.shinde »

Thanks RoryOF,

I am trying to do it pragmatically, can you please help.

Thanks
Sachin
OpenOffice 4.1.3 Windows 10
User avatar
Villeroy
Volunteer
Posts: 31269
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Deleting MACRO from DOC/DOCX/ODT File

Post by Villeroy »

Code: Select all

libs = ThisComponent.BasicLibraries
for each s in libs.getElementNames()
	libs.removeLibrary(s)
next
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
sachin.shinde
Posts: 4
Joined: Fri Jul 21, 2017 2:02 pm

Re: Deleting MACRO from DOC/DOCX/ODT File

Post by sachin.shinde »

Thanks Villeroy,

can please help me to with C# code.

Thanks,
Sachin
OpenOffice 4.1.3 Windows 10
User avatar
Villeroy
Volunteer
Posts: 31269
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Deleting MACRO from DOC/DOCX/ODT File

Post by Villeroy »

You are the C# developer. I don't even have a Windows machine. You should know how to connect with a running instance of your office suite and get a reference to a document. In my macro code "ThisComponent" refers to the currently active document.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
sachin.shinde
Posts: 4
Joined: Fri Jul 21, 2017 2:02 pm

Re: Deleting MACRO from DOC/DOCX/ODT File

Post by sachin.shinde »

I have checked in code for "Document", it does not have any method "BasicLibraries" in C# assemblies/DLLs. I got, its hard get answers here for C# related queries for OPenOffice SDK.

Thanks for your time.
OpenOffice 4.1.3 Windows 10
User avatar
Villeroy
Volunteer
Posts: 31269
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Deleting MACRO from DOC/DOCX/ODT File

Post by Villeroy »

[Tutorial] Introduction into object inspection with MRI
Install MRI. It produced the following code for me:

Code: Select all

using System;
using unoidl.com.sun.star.beans;
using unoidl.com.sun.star.container;
using unoidl.com.sun.star.lang;
using unoidl.com.sun.star.script;
using unoidl.com.sun.star.uno;

public class Snippet {
public void snippet(XComponentContext xContext, object oInitialTarget)
{
	try
	{
		XPropertySet xPropSet = (XPropertySet)oInitialTarget;
		XLibraryContainer xLibraryContainer = (XLibraryContainer) xPropSet.getPropertyValue("BasicLibraries").Value;
		
		XNameAccess xNameAccess = (XNameAccess) xLibraryContainer;
		XNameAccess xNameAccess_2 = (XNameAccess) xNameAccess.getByName("Standard").Value;
	}
	catch (RuntimeException e)
	{
		// getByName
		Console.WriteLine(e.Message);
	}
	catch (WrappedTargetException e)
	{
		// getPropertyValue, getByName
		Console.WriteLine(e.Message);
	}
	catch (UnknownPropertyException e)
	{
		// getPropertyValue
		Console.WriteLine(e.Message);
	}
	catch (NoSuchElementException e)
	{
		// getByName
		Console.WriteLine(e.Message);
	}
}
}[
object oInitialTarget is the document in question
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Post Reply