Page 1 of 1

Insert Macro

PostPosted: Wed Dec 17, 2014 1:53 am
by towa
Hello,

in this post http://www.docx4java.org/forums/docx-java-f6/inserting-macros-t238.html?sid=02307b3ab8eec11148dba3f358509b92 the question was answert. The problem is, the solution do not work anymore. Up to version 2.8.1.12 everything was fine. Since version 3 the function org.docx4j.openpackageing.parts.WordprocessingML.VbaDataPart.setDocument not longer exists.

So i'd like to ask, how it is now realised to import macros from vbaProject.bin and vbaData.xml?

Regards
Towa

Re: Insert Macro

PostPosted: Thu Dec 18, 2014 2:06 pm
by jason
Try vbaData.unmarshal instead of setDocument

Please confirm that works :-)

Re: Insert Macro

PostPosted: Thu Apr 28, 2016 2:31 am
by fredguinog
Hi, I tried to execute the code above using vbaData.unmarshal instead of setDocument with docx4j-3.0.0 and the result of the vbaData.xml inside the container was missing same attributes.

my working vbaData.xml manually extracted from a docm file:
Code: Select all
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<wne:vbaSuppData xmlns:wpc="http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:wp14="http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml" xmlns:w15="http://schemas.microsoft.com/office/word/2012/wordml" xmlns:wpg="http://schemas.microsoft.com/office/word/2010/wordprocessingGroup" xmlns:wpi="http://schemas.microsoft.com/office/word/2010/wordprocessingInk" xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml" xmlns:wps="http://schemas.microsoft.com/office/word/2010/wordprocessingShape" mc:Ignorable="w14 w15 wp14"><wne:mcds><wne:mcd wne:macroName="PROJECT.NEWMACROS.AUTOOPEN" wne:name="Project.NewMacros.AutoOpen" wne:bEncrypt="00" wne:cmg="56"/></wne:mcds></wne:vbaSuppData>


the result vbaData.xml inside the container after the code execution:
Code: Select all
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><wne:vbaSuppData xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:w15="http://schemas.microsoft.com/office/word/2012/wordml" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math" xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:ns9="http://schemas.openxmlformats.org/schemaLibrary/2006/main" xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml" xmlns:c="http://schemas.openxmlformats.org/drawingml/2006/chart" xmlns:ns12="http://schemas.openxmlformats.org/drawingml/2006/chartDrawing" xmlns:dgm="http://schemas.openxmlformats.org/drawingml/2006/diagram" xmlns:pic="http://schemas.openxmlformats.org/drawingml/2006/picture" xmlns:xdr="http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing" xmlns:dsp="http://schemas.microsoft.com/office/drawing/2008/diagram" xmlns:ns17="urn:schemas-microsoft-com:office:excel" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:ns21="urn:schemas-microsoft-com:office:powerpoint" xmlns:ns23="http://schemas.microsoft.com/office/2006/coverPageProps" xmlns:odx="http://opendope.org/xpaths" xmlns:odc="http://opendope.org/conditions" xmlns:odq="http://opendope.org/questions" xmlns:oda="http://opendope.org/answers" xmlns:odi="http://opendope.org/components" xmlns:odgm="http://opendope.org/SmartArt/DataHierarchy" xmlns:ns30="http://schemas.openxmlformats.org/officeDocument/2006/bibliography" xmlns:ns31="http://schemas.openxmlformats.org/drawingml/2006/compatibility" xmlns:ns32="http://schemas.openxmlformats.org/drawingml/2006/lockedCanvas"><wne:mcds><wne:mcd/></wne:mcds></wne:vbaSuppData>


If I edit the vbaData.xml replacing <wne:mcd/> with <wne:mcd wne:macroName="PROJECT.NEWMACROS.AUTOOPEN" wne:name="Project.NewMacros.AutoOpen" wne:bEncrypt="00" wne:cmg="56"/>, I can open the macro dialog of the created document using Word app without problems.

Does anyone have any idea why?

Thanx

Re: Insert Macro

PostPosted: Thu Apr 28, 2016 5:43 pm
by jason
Tested https://github.com/plutext/docx4j/blob/ ... roAdd.java just now in docx4j 3.3.0; works as expected.

Looks like the relevant fix may have been made in March 2014. https://github.com/plutext/docx4j/commi ... d/offmacro

So its probably in v3.1.0, but not 3.0.0.