Jump to content

How to use array of strings as argument of a function call


Recommended Posts

This works:

$oExcel.Application.Union($oExcel.Application.ActiveSheet.Range("A2:K9"),$oExcel.Application.ActiveSheet.Range("A12:K19")).Select

But this dont:

$Range[0] = '$oExcel.Application.ActiveSheet.Range("A2:K9")'
$Range[1] = '$oExcel.Application.ActiveSheet.Range("A12:K19")'
$oExcel.Application.Union($Range[0],$Range[1]).Select

How can i make it work ?

I am planning on converting the array to a string and paste it as argument of the union as the number of ranges to be combined varies.

Link to comment
Share on other sites

  • Moderators

Juvigy, you've been around long enough to know better than to post non-runnable code with nothing more than "it's broke" as an explanation. Why are you not using the built in Excel functions? This snippet (bare minimum since you haven't shown us what you're actually trying to accomplish) returns the ranges you're after:

#include <Excel.au3>

$oExcel = _Excel_Open()
$oWorkbook = _Excel_BookOpen($oExcel, @DesktopDir & "\Test.xls", True)
$param1 = _Excel_RangeRead($oWorkbook, Default, "A2:K9")
$param2 = _Excel_RangeRead($oWorkbook, Default, "A12:K19")

From there you can convert your array to a string (_ArrayToString) or manipulate however you need to.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

I think you didnt get what i was trying to do or i didnt explain it right. Anyway - i found how to do it :

Execute("$oExcel.Application.Union("&$Range[0]&","&$Range[1]&").Select")

I had forgotten the execute command and couldnt find it , but eventually i did.

@EDIT

Here is what i wanted to do:

$parameter = "$oExcel.Application.Union("&_ArrayToString($Range,",")&").Select"
Execute($parameter)

 

Edited by Juvigy
solution
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...