Jump to content

Excel troubles...


Azazel
 Share

Recommended Posts

Hi everybody,

My goal is to write and read some datas in a excel sheet .

I want to read the cell (1,2) and use this data to fill the name of the book in "Save as"

I'm in front of 2 errors and crashes

I use Autoit v3.2.13.13 (beta)

Souce code :

#include <Excel.au3>
#include <Date.au3>
$oMyError = ObjEvent("AutoIt.Error", "MyErrFunc"); Install a custom error handler
$date=@MDAY&"/"&@MON&"/"&@YEAR

$oExcel = _ExcelBookNew()

_ExcelWriteCell($oExcel, $date, 1, 1);Write to the Cell

while 1
$name = _ExcelReadCell($oExcel, 1, 2)
if $name<>"" Then
ExitLoop
EndIf
Sleep(500)
WEnd
WinWait("Save As","")
ControlSetText( "Save As", "", "[CLASS:RichEdit20W; INSTANCE:2]", @ScriptDir&"\"&@YEAR&"\SEM "&_WeekNumberISO()&$name&".xls")
Exit

Func MyErrFunc()
;Avoid CRASH
EndFunc ;==>MyErrFunc

First Crash :

If in don't use a "Install a custom error handler" when i start to fill the cell (1,2) i have this message :

C:\Program Files\AutoIt3\beta\Include\Excel.au3 (685) : ==> The requested action with this object has failed.:

Return $oExcel.Activesheet.Cells($sRangeOrRow, $iColumn).Value

Return $oExcel.Activesheet^ ERROR

I use a error handler to solve the problem

Second crash :

If i use the error handler and i close the Excel sheet before opening "Save as" i have this message :

C:\Program Files\AutoIt3\beta\Include\Excel.au3 (685) : ==> Missing right bracket ')' in expression.:

Return $oExcel.Activesheet.Cells($sRangeOrRow, $iColumn).Value

Return ^ ERROR

Please help me for debugging my script

Best regards

Marc

Edited by Azazel
Link to comment
Share on other sites

Hi,

Is the value of cell 1,2 set by you the user or is it already present in the excel file?

From what I can see, excel doesn't like it if you read a cell while it is being updated, I'll have a look to see if there's a way to test if the cell is selected.

Brett

Link to comment
Share on other sites

Hi,

Is the value of cell 1,2 set by you the user or is it already present in the excel file?

From what I can see, excel doesn't like it if you read a cell while it is being updated, I'll have a look to see if there's a way to test if the cell is selected.

Brett

Hi,

The cell 1,2 is set by the user

When the Excel sheet is start this cell is blank

Best regards

Link to comment
Share on other sites

Why not write it using AutoIt then? Just a simple matter of using Input box etc.

Otherwise we need to have this then:

But not too sure how to implement it :)

http://msdn.microsoft.com/en-us/library/aa...office.11).aspx

My collegues use this excel sheet to send spare parts to customers, i don't want to interract with there job with a input box

i just want to read the datas they fill in to generate the "Save as" name

Link to comment
Share on other sites

My collegues use this excel sheet to send spare parts to customers, i don't want to interract with there job with a input box

i just want to read the datas they fill in to generate the "Save as" name

From your description of what you are trying to achieve, I would suggest that this is not a job for AutoiIt. I would be easier and simpler to code a function to do this using Excels own VBA to intercept the save event. Edited by Bowmore

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook

Link to comment
Share on other sites

From your description of what you are trying to achieve, I would suggest that this is not a job for AutoiIt. I would be easier and simpler to code a function to do this using Excels own VBA to intercept the save event.

I understant your opinion, unfortunatly, the script i put here is a small part of a bigger AutoIt program

So i need your help to make it works

Thanks a lot

Marc

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...