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

I am trying to convert below VBA code to WIN32::OLE equivalent
Range("A1").Select With Selection.Interior .ColorIndex = 8 .Pattern = xlSolid End With
I wrote some thing like
PERL --> $app->Range("A1")->Select with Selection->Interior({'ColorIndex' +} => 8,{'Pattern'} => "xlSolid");
But it is not working monk's blessing required

Replies are listed 'Best First'.
Re: HELP in VBA to WIN32::OLE
by Corion (Patriarch) on Mar 16, 2008 at 13:04 UTC

    Where does the with keyword come from and what do you think it does?

    If you want a really verbatim translation, you need to replace the With X from VB with for (X) { in Perl:

    for ($app->Selection) { $_->{ColorIndex} = 8; };

    I recommend that you instead move away from the (application) global variables like $app->Selection and instead use Perl variables:

    my $sel = $app->Range("A1"); my $interior = $sel->Interior; $interior->{ColorIndex} = 8; $interior->{Pattern} = xlSolid;

    If you want to translate from VB to Perl, you need to know about both languages. Wild throwing around of keywords and syntax won't get you far.

Re: HELP in VBA to WIN32::OLE
by igelkott (Priest) on Mar 16, 2008 at 13:09 UTC

    The question is a bit short on context but here's a few Perl fragments which might be applicable (untested, to say the least):

    $Range = $Sheet->Range("A1"); $Range->Select; $Excel->Selection->Interior({ColorIndex => 8,Pattern => "xlSolid"});

    This is assuming Excel and that the sheet has been activated, etc.

    HTH