Page 1 of 1

Deleting MACRO from DOC/DOCX/ODT File

PostPosted: Fri Jul 21, 2017 2:14 pm
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

Re: Deleting MACRO from DOC/DOCX/ODT File

PostPosted: Fri Jul 21, 2017 2:22 pm
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.

Re: Deleting MACRO from DOC/DOCX/ODT File

PostPosted: Fri Jul 21, 2017 2:28 pm
by sachin.shinde
Thanks RoryOF,

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

Thanks
Sachin

Re: Deleting MACRO from DOC/DOCX/ODT File

PostPosted: Fri Jul 21, 2017 3:48 pm
by Villeroy
Code: Select all   Expand viewCollapse view
libs = ThisComponent.BasicLibraries
for each s in libs.getElementNames()
   libs.removeLibrary(s)
next

Re: Deleting MACRO from DOC/DOCX/ODT File

PostPosted: Mon Jul 24, 2017 8:27 am
by sachin.shinde
Thanks Villeroy,

can please help me to with C# code.

Thanks,
Sachin

Re: Deleting MACRO from DOC/DOCX/ODT File

PostPosted: Mon Jul 24, 2017 11:42 am
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.

Re: Deleting MACRO from DOC/DOCX/ODT File

PostPosted: Mon Jul 24, 2017 12:09 pm
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.

Re: Deleting MACRO from DOC/DOCX/ODT File

PostPosted: Mon Jul 24, 2017 3:39 pm
by Villeroy
[Tutorial] Introduction into object inspection with MRI
Install MRI. It produced the following code for me:
Code: Select all   Expand viewCollapse view
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