Jump to content

Script won't run


ClayR
 Share

Recommended Posts

Run("M:\The Park\Barossa @ The Park\Leasing Workbench\Workbench live Barossa 6-17-10.xls")

Sleep(5000)

Send("{ENTER}")

Sleep(2000)

WinClose("Microsoft Excel")

Send("{ENTER}")

Super simple script...but all it does is just open instance after instance, and never actually does anything listed above. Thinking it was perhaps the file (and not the code), I copied this into a working script and removed all the coding except theses lines above with the same result.

Link to comment
Share on other sites

Look at this example. (from the helpfile, _ExcelBookOpen )

#include <Excel.au3>

$sFilePath1 = @ScriptDir & "\Test1.xls" ;This file should already exist

$oExcel = _ExcelBookOpen($sFilePath1)

If @error = 1 Then

MsgBox(0, "Error!", "Unable to Create the Excel Object")

Exit

ElseIf @error = 2 Then

MsgBox(0, "Error!", "File does not exist!")

Exit

EndIf

Edited by MPH
Link to comment
Share on other sites

You are starting the script by double-clicking the file in Explorer and as Run() fails you have the script start itself when it presses Enter.

You really should try the Excel UDF instead, as MPH said.

Link to comment
Share on other sites

You really should try the Excel UDF instead, as MPH said.

Or the COM objects of excel are very well documented and pretty easy to use...

$oEX = ObjCreate("","excel.Application")
$oWb = $oEX.Workbooks.Add("Whatever.xls")
$oWb.Activesheet.range("a1").formula = "I'm Cell A1!")
sleep(1000)
$oWb.Activesheet.range("a1").formula = "but i'm going away and taking my row with me")
$oAS = $oWb.Activesheet;could have done this earlier but just showing how easy it is to do different things
$oAS.Rows("1:1").delete
MsgBox(0,"finished","playtime is over")
$oEX.Quit
Link to comment
Share on other sites

Thanks guys for the prompt help- I will play around with these options.

Or the COM objects of excel are very well documented and pretty easy to use...

$oEX = ObjCreate("","excel.Application")
$oWb = $oEX.Workbooks.Add("Whatever.xls")
$oWb.Activesheet.range("a1").formula = "I'm Cell A1!")
sleep(1000)
$oWb.Activesheet.range("a1").formula = "but i'm going away and taking my row with me")
$oAS = $oWb.Activesheet;could have done this earlier but just showing how easy it is to do different things
$oAS.Rows("1:1").delete
MsgBox(0,"finished","playtime is over")
$oEX.Quit

Link to comment
Share on other sites

The udf IS com-objects.

No, the UDF is a collection of user defined functions that interact with the COM objects to allow an "autoit feel". That's why you call _ExcelBookOpen($sFilePath1) instead of $oEX.Workbooks.Add($aFilePath1). Personally i'd rather interact with the objects DIRECTLY because the method names tend to be shorter than the function names, and i don't think that there are FUNCTIONS in the UDF for every property or method of every office object. So rather than hunting through a udf to find the function to do what i want, and see how the UDF writer wants me to call it, i can look in the object browser in VBA (F2) and see every member that can be accessed explicitly.
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...