All I can suggest is to study the spec and write a decoder of VBA. I recall that macro code is compressed but it is not PKZIP but some other compression algorithm.
If it is so, try to decompress your files first. I can't tell you exactly what to do - extracting VBA code is a big task and potentially can take days or weeks of work. Cheers, Yegor On Sat, Apr 28, 2012 at 11:32 AM, Andrey Yesyev <[email protected]> wrote: > Hey guys! > > I'm working on the same issue, getting macros code from XLS file. > I got VBA modules raw data htis way > > HSSFWorkbook wb = new HSSFWorkbook(is); > > ExcelExtractor extractor = new ExcelExtractor(wb); > > List<HSSFObjectData> l = wb.getAllEmbeddedObjects(); > DirectoryEntry root = extractor.getRoot(); > for(Entry entry:root){ > if(entry.isDirectoryEntry()){ > DirectoryEntry dirEntry = > (DirectoryEntry)entry; > if(dirEntry.hasEntry("VBA")){ > DirectoryNode node = > (DirectoryNode) dirEntry.getEntry("VBA"); > for(Entry e:node){ > DocumentNode docNode = > (DocumentNode)e; > > if(!docNode.getName().startsWith("dir") && > > !docNode.getName().startsWith("_VBA_PROJECT") && > > !docNode.getName().startsWith("__SRP")){ > > System.out.println(docNode.getName()); > > DocumentInputStream dis = new DocumentInputStream(docNode); > byte[] data = > IOUtils.toByteArray(dis); > > FileOutputStream fos = new > FileOutputStream("C:/"+docNode.getName()+"_data.txt"); > > fos.write(data); > fos.close(); > } > } > } > } > } > > So I had 4 files. Sheet1_data.txt upto Sheet3_data.txt and > ThisWorkbook_data.txt. > My macros is in the ThisWorkbook_data.txt. But the problem is that I don't > recognize the format of these files as format of VBA module, described in > [MS-OVBA].pdf. > > Any ideas? > > -- > View this message in context: > http://apache-poi.1045710.n5.nabble.com/DO-NOT-REPLY-Bug-52949-New-How-to-extract-VBA-Macros-code-from-Excel-file-by-using-POI-tp5579175p5672215.html > Sent from the POI - Dev mailing list archive at Nabble.com. > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [email protected] > For additional commands, e-mail: [email protected] > --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
