Excel automation (Intermediate)

We will now use an Excel SpreadSheet from AutoIt macros, so we replace Visual Basic for applications (VBA) as it is buggy switching macros between different Office versions.

Getting ready

You must have MS Excel and AutoIt.

Open the SciTE code editor and start writing the Excel automation code (called macros).

How to do it...

Follow these steps to automate Excel:

  1. Copy and paste the source code, and press F5 to run the following script:
    $oExcel = ObjCreate("Excel.Application") 
    ; Create an Excel Object 
    $oExcel .Visible = 1 
    With $oExcel ; Let Excel show itself 
    .WorkBooks.Add ; Add a new workbook 
    .Worksheets(1).ScrollArea = "A50" ; got to A50
    .Activewindow.ScrollColumn = 50 ; Go to column
    .Activewindow.ScrollRow = 50 ;Go to row
    .cells(50,1).value=44 ; writting values
    EndWith 
    How to do it...
    How to do it...

How it works...

You can use Office objects this way to automate Word, Excel, and others same as given in the previous recipe about AutoIt and batch files replacement; you can replace Visual Basic for Applications (VBA) using AutoIt macros. You can even use a Microsoft object for these macros. Further information about Excel automation and VBA can be found at http://www.autoitscript.com/forum/topic/144031-update-the-excel-udf-that-comes-with-autoit/.

There is another approach. It is by simulating keyboard strokes (send()) and mouse clicks (MouseClick()) for very simple macros. You simulate a human user by repeating the same keystrokes and mouse movements he would do when sitting in front of his/her computer.

Of course, these macros are not human beings; they do not think yet, but you can use some if...then clauses to identify possible or typical problems that may arise when you computers are working, and solve these forks with new macros, or by reusing previous ones. So, you will make your macro a little more intelligent than the typical word processor computer.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset