Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Excel’s Select and Activate considered harmful

by moritz (Cardinal)
on Mar 02, 2011 at 11:46 UTC ( #890964=note: print w/ replies, xml ) Need Help??


in reply to Excel’s Select and Activate considered harmful

So when I want to automate something, and the macro recorder uses Select, how do I rewrite it not to use Select?

It's good to warn against harmful practise, but if you offer no alternatives, your effort will most likely be lost.


Comment on Re: Excel’s Select and Activate considered harmful
Re^2: Excel’s Select and Activate considered harmful
by davies (Vicar) on Mar 02, 2011 at 11:52 UTC

    Create your own object and assign to that. To give an example, instead of

    $sht->Range("A1")->Select;
    use
    my $rng = $sht->Range("A1");
    Then, rather than Selection->, use $rng->. Obviously, it's better to use a descriptive name rather than $rng.

    Regards,

    John Davies

Re^2: Excel’s Select and Activate considered harmful
by dasgar (Deacon) on Mar 04, 2011 at 06:29 UTC

    Usually in the code that I've written, I'm interested in reading from or writing to a cell and I don't need or want to keep a reference around for that cell. In my case, I just skip the selection step altogether with code like:

    my $value = $sht->Range("A1")->{Value};

    or

    $sht->Range("A1")->{Value} = $value;

    Just tossing out a suggestion (hopefully a correct and useful one) about how to avoid using Select.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (8)
As of 2014-12-25 21:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (163 votes), past polls