Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Pass arguments to VBA macro

by prasadbabu (Prior)
on May 11, 2007 at 09:32 UTC ( #614858=perlquestion: print w/ replies, xml ) Need Help??
prasadbabu has asked for the wisdom of the Perl Monks concerning the following question:

Monks,

I am calling a dot file named vad.dot and it has a macro sub vad (path as string)...
I want to pass the parameter to this macro from Perl using Win32::OLE.

use Win32::OLE; use Win32::OLE qw(in with); use Win32::OLE::Const 'Microsoft Word'; $Win32::OLE::Warn = 2; # Throw Errors, I'll catch them ################################# Get the word object ################ my $word = Win32::OLE->GetActiveObject('Word.Application') || Win32::OLE->new('Word.Application', 'Quit'); #get the word +object $word->Documents->Add || die("Unable to create document ", Win32::OLE- +>LastError()); ################## Call the vad macro to create table ##### $word->AddIns->Add({Filename=>"$cur_dir\\vad.dot", Install=>"True"}); #$word->run("vad") #running fine $word->run("vad", "D:\\Prasad\\Projects\\tools\\vad"'); #getting error
Previously, When I ran my tool without parameters for my macro, it was working fine.
Could someone tell me how to pass arguments?
This is the error I am getting,
OLE exception from "Microsoft Word": Unable to run the specified macro Win32::OLE(0.1707) error 0x80020003: "Member not found" in METHOD/PROPERTYGET "run" at D:\Prasad\Projects\tools\vad\vad.pl + line 314
In VBA macro,
sub vad(path as string) { }
updated: added macro skeleton and fixed typos.

Thanks in advance

Prasad

Comment on Pass arguments to VBA macro
Select or Download Code
Re: Pass arguments to VBA macro
by marto (Chancellor) on May 11, 2007 at 09:50 UTC
    Typo:
    $word->run("vad", "D:\\Prasad\\Projects\\tools\\vad"');
    should be
    $word->run("vad", "D:\\Prasad\\Projects\\tools\\vad");

    And:
    #$word->run("vad")       #running fine
    should be:
    #$word->run("vad");       #running fine

    A working example based on what you have
    use strict; use warnings; use Win32::OLE; use Win32::OLE qw(in with); use Win32::OLE::Const 'Microsoft Word'; $Win32::OLE::Warn = 2; # Throw Errors, I'll catch them my $word = Win32::OLE->GetActiveObject('Word.Application') || Win32::OLE->new('Word.Application', 'Quit'); #get the word ++object $word->Documents->Add || die("Unable to create document ", Win32::OLE- +>LastError()); $word->run("test", "D:\\Prasad\\Projects\\tools\\vdd");
    With a word macro:
    Sub test(teststring as String) MsgBox(teststring) End Sub
    Works as expected

    Update: Removed redundant br tag

    Martin

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://614858]
Approved by varian
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (2)
As of 2014-08-31 01:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (294 votes), past polls