tags:

views:

189

answers:

2

I have a Perl script that can define and write a MS Word macro according to the user's input.

But how can I make the Perl script open Word and add the macro into its macros data base?

+2  A: 

You can do that by accessing the VBProject property of the document. However, with recent versions of Microsoft Office, you will likely get:

OLE exception from "Microsoft Word":

Programmatic access to Visual Basic Project is not trusted.

See You may receive an run-time error when you programmatically allow access KB article for more information.

Or, you can try to do it the primitive way by sending keystrokes to Word using Win32::GuiTest.

Sinan Ünür
A: 

Thank you Sinan.

  1. Since you say that VBProject doesn't always work, then it's not an option for me...

  2. Sorry for my complete ignorance... but what is "Win32::GuiTest" ? Can you please give me an example of how to add a Macro to Word from within a perl script (or even straight from the dos-cmd-line) ?

Thanks a lot, Roni

Roni
@Roni 1) Do not post non-answer answers. You should have posted a comment to my answer here. 2) I have linked to the KB article about why you would receive a security exception -- did you read that? You would get that exception in any language not just Perl, due to the nature of what you are trying to do: It can be used to write trojan horses. 3) I did link to the documentation for `Win32::GuiTest` -- feel free to read it. However, I will not post here a guide for script kiddies. The GuiTest docs are easy to follow and understand for someone who knows Perl.
Sinan Ünür
I was just being polite. Your answer was not so helpful, since "You can do that by accessing the VBProject property" does not say much for someone who asked exactly that - how can that be done. And the GUI is totally not the right answer for someone who asked how can it be done form a Perl batch script. Still, having all that said, I still thank you for your effort and hope you won't get angry at other "kiddies", it's not good for your health. Take it easy...
Roni