RFC: Macro support for Excel::Writer::XLSX

268 views
Skip to first unread message

jmcnamara

unread,
Nov 23, 2012, 12:50:12 PM11/23/12
to Spreadsheet::WriteExcel
Hi,

I am considering adding pseudo-macro support to Excel::Writer::XLSX.

The mechanism would be to extract one or more macro files from an
existing XLSM workbook and add them to a new Excel::Writer::XLSX file.
A sample application to extract the macros would be provided.
Something like:

./extract_vba somefile.xlsm
Extracting...
VBAProject.bin

Then in a Excel::Writer::XLSX program:

use strict;
use Excel::Writer::XLSX;

my $workbook = Excel::Writer::XLSX->new( 'sample.xlsx' );
my $worksheet = $workbook->add_worksheet();
...

$workbook->insert_vbaproject('VBAProject.bin');
...

It probably won't be possible to tie the macros to any functionality
in the Excel::Writer::XLSX workbook such as buttons or dropdowns. The
macros would just be in the file if the user needed them.

Comments, ideas, suggestions?

John.
--

jmcnamara

unread,
Nov 23, 2012, 12:53:06 PM11/23/12
to Spreadsheet::WriteExcel
Hi,

I forgot to add.

The reason for doing it like this is that the macros are stored in an
undocumented binary format. I.e., it wouldn't be feasible to create
them programmatically.

John.
--

Hiroshi, YOSHIDA

unread,
Nov 24, 2012, 12:45:11 AM11/24/12
to spreadsheet...@googlegroups.com
Hi,


DBCS compatibility problem is still remained in 'vbaProject.bin'.

Kanji or any Double-byte charactors are written by MS-KANJI or
other LOCAL Code in this file, so when you load macro with the
future "The mechanism", you should open .XLSM with your EXCEL
at first and check whether an imcompatible chars would be found
or not.


--
Hiroshi, YOSHIDA

jmcnamara

unread,
Nov 24, 2012, 12:51:56 PM11/24/12
to Spreadsheet::WriteExcel

On Nov 24, 5:45 am, "Hiroshi, YOSHIDA" <kann...@gmail.com> wrote:
> DBCS compatibility problem is still remained in 'vbaProject.bin'.

Hi,

Thanks for that. I'm sure there will be a lot of issues to work out.

Perhaps you can try the pre-release version and let me know how you
get on. See my other post for details.

John

jmcnamara

unread,
Nov 24, 2012, 12:52:46 PM11/24/12
to Spreadsheet::WriteExcel
Hi,

I've uploaded a pre-release version of macro support in
Excel::Writer::XLSX to the vba branch of the Github repository.

    https://github.com/jmcnamara/excel-writer-xlsx/tree/vba

There is an example file the imports a VBA project to enable macros:

    https://raw.github.com/jmcnamara/excel-writer-xlsx/vba/examples/add_vba_project.pl

There is also a utility called, extract_vba, that extracts the
required vbaProject binary from an existing Excel xlsm file:

    https://raw.github.com/jmcnamara/excel-writer-xlsx/vba/bin/extract_vba

This utility is installed by default if you do a full "make install".

There are probably issues with this (for example codenames aren't
currently supported). If you try it out let me know how you get on.

John











Richard Noble

unread,
Nov 25, 2012, 11:32:45 PM11/25/12
to spreadsheet...@googlegroups.com
John;

As the user would have to tie the macro in any way, I don't see the need for this unless there is a method to automatically call macros that auto run on open. 

Keep up the great work.....

jmcnamara

unread,
Nov 26, 2012, 4:28:48 AM11/26/12
to Spreadsheet::WriteExcel


On Nov 26, 4:32 am, Richard Noble <rpno...@ibksoftware.com> wrote:

> As the user would have to tie the macro in any way, I don't see the need
> for this unless there is a method to automatically call macros that auto
> run on open.

Hi Richard,

That is a fair point. As it stands there isn't much advantage to
embedding macros in an E::W::X file as opposed to calling them from
another workbook.

However, I think that once the basic mechanism is in place I should be
able to add some form controls to run the macros. The first pass will
be a button element and I may add dropdowns and checkboxes in time
(each of these represents quite a bit of work so I'll have to roll
them out bit by bit).

So, if anyone wants to comment on how they would use macros via form
controls please do.

John.
--

Richard Noble

unread,
Nov 26, 2012, 8:21:17 PM11/26/12
to spreadsheet...@googlegroups.com
I see that working if the Excel designer ties the macro to a button to compute a result or speed the process of data entry... Have fun....

Francois Tremblay

unread,
May 24, 2014, 11:54:53 PM5/24/14
to spreadsheet...@googlegroups.com
Embedding macros is great.  All I have to do now is copy the scroll bars from another workbook and paste and it works right away!

If you implemented insert_scrollbar() it would make my day!

Thanks,

Francois


On Monday, November 26, 2012 4:28:49 AM UTC-5, jmcnamara wrote:

jmcnamara

unread,
May 26, 2014, 5:50:20 AM5/26/14
to spreadsheet...@googlegroups.com
On Sunday, 25 May 2014 04:54:53 UTC+1, Francois Tremblay wrote:
Embedding macros is great.  All I have to do now is copy the scroll bars from another workbook and paste and it works right away!

If you implemented insert_scrollbar() it would make my day!

Hi Francois,

Unfortunately adding new VBA object types is a *lot* of work since they need to be implemented in VML which is an under-documented XML-ish format that somehow found its way into the Office OpenXML specification.

So it is unlikey that any VBA objects other than "Button" will be added to Excel::Writer::XLSX.

John

 
Reply all
Reply to author
Forward
0 new messages