Jump to content
Sign in to follow this  
Juvigy

Little help with a VBA script

Recommended Posts

Juvigy

The line i got trouble with is :

Range(Selection, Selection.End(xlDown)).Select

I tried :

$oExcel.ActiveSheet.Range($oExcel.Selection , $oExcel.Selection.End(-4121)).Select

and

$oExcel.ActiveSheet.Range(.Selection , .Selection.End(-4121)).Select

but it doesnt work.

I got errors like :

.Range($oExcel.Selection , $oExcel.Selection.End(-4121)).Select

.Range($oExcel.Selection ^ ERROR

Share this post


Link to post
Share on other sites
GodlessSinner

Now I have'nt installed MSOffice, so try it yourself:

#Include <Excel.au3>
$oExcel = ObjCreate("Excel.Application")
;$oExcel.visible =1
;$oExcel.workbooks.add
With $oExcel.ActiveSheet
    .Range(.Selection , .Selection.End(-4121)).Select
EndWith

_____________________________________________________________________________

Share this post


Link to post
Share on other sites
zfisherdrums

Hello Juvigy!

I found many time that errors I encountered when porting VBA to AutoIt, it was necessary to reference certain objects from $oExcel.Application. For example:

$oExcel.ActiveSheet.Range( $oExcel.Application.Selection, $oExcel.Application.Selection.End(-4121) ).Select

And as Vitas pointed out, you can use "With":

With $oExcel.Application

$oExcel.ActiveSheet.Range( .Selection, .Selection.End(-4121)).Select

EndWith

Hope this helps!

Zach...

Share this post


Link to post
Share on other sites
Juvigy

Thank you for the pointers Guys!

Turned out you have to put the whole "path" of the object in AutoIt which is not like this in VBA:

VBA:

Range(Selection, Selection.End(xlDown)).Select

=

AutoIT

$oExcel.Application.ActiveSheet.Range($oExcel.Application.Selection , $oExcel.Application.ActiveSheet.Range("A2").End(-4121)).Select

Sometimes you can skip part of the "path" but this quite often leads to logic faults difficult to grasp.

PS. The above code selects all the used cells from a row bellow the currently selected cell.

Edited by Juvigy

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.