flow3rgirlz has asked for the wisdom of the Perl Monks concerning the following question:

Hi all, I tried to run this code
#!/usr/bin/perl use Win32::OLE qw(in with); use Win32::OLE::Const 'Microsoft Visio'; my $Visio = Win32::OLE->new('Visio.Application'); $MacroName = "Stencil"; #Running a macro $visiofile = "d:\\VisioProject\\StencilProject.vsd"; my $Doc = $Visio->{'Documents'}->Open($visiofile); $Visio->Run($MacroName); $Visio->Quit
When i run the similar code in Word, it does run the macro. But when i try in Visio, it just open the doc without running the macro. Can anyone help me what's wrong with my code. I try to search the running macro method for visio but i just couldnt find it. I really need some help here as i stuck in this quite a long time. Thanks for help.

Replies are listed 'Best First'.
Re: run visio macro in perl
by sflitman (Hermit) on Jan 08, 2009 at 04:57 UTC
    I think you need to know the OLE methods defined by $Visio. I found this article which shows Visual Basic code accessing the same object. Perhaps Run is like Open, you have to run it on the {'Documents'} hash? I don't have Visio so I'm not sure. Microsoft tends to think of macros as being associated with the document tree, I've noticed.

    (Major digression: why not use a better and more cross-platform diagramming app like Inkscape? Does SVG, which has CPAN modules to directly manipulate, much more powerful and Perlish!)

    HTH, SSF

      Thanks for your reply. I found another method which automatically runs the macro once you open the Visio file. So, basically rather than run the macro from perl, i just open the visio file from perl and it will automatically runs the macro as well.