Jump to content

Excel closed independantly


myids
 Share

Recommended Posts

Could find this topic through search:

If $oExcel Then
        $Index = 0
        For $i = 1 To 200 ;Loop
            $cindex = $Index + 1
            $sCellValue = _ExcelReadCell($oExcel, $i, 1)
            $cell_net = StringStripWS($sCellValue, 3)
            If $cell_net = "Netname" Then
                $cell_net = ""
            EndIf
            ;ConsoleWrite( $cell_net & @CRLF)
            ;MsgBox(0, "", "cell_net is: " & @CRLF & $cell_net, 2)
            If StringLen($cell_net) Then
                $nlgth = FindNetinArray($cell_net)
                _ExcelWriteCell($oExcel, $nlgth, $i, 2)
            EndIf
            $Index = $Index + 1
        Next
    Else
        $oExcel = ""
        MsgBox(0, "SpreadSheet Was Not Open", "SpreadSheet Was Not Open" & @CRLF & "Open Spreadsheet, to Run a Length Check")
        ;OpenSS()
    EndIf

this is part of a function that is called after Excel is opened previous using _ExcelBookOpen.

It's possible to run this function from a menu. If Excel was closed via an Excel menu File/Exit then $oExcel in Null and fails the branch.

After re-opening the same exact file, $oExcel should be re-initialized but still fails the branch.

I have tried testing $oExcel.ActiveSheet.Name and others like $oExcel.ActiveWorkBook.Sheets.Count. But since the object doesn't exist any longer, the script crashes.

Any ideas how I can check if the object exists before testing the object property?

TIA

Link to comment
Share on other sites

This is the error message for testing with IsObj($oExcel):

C:\Program Files (x86)\AutoIt3\Include\Excel.au3 (694) : ==> Variable must be of type "Object".:

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

Return $oExcel.Activesheet^ ERROR

At this point, $oExcel was closed, but AutoIt script does not know it, so, still falls through as if true and is crashing on the first object function:

$sCellValue = _ExcelReadCell($oExcel, $i, 1)

If IsObj($oExcel) Then
        $Index = 0
        For $i = 1 To 200 ;Loop
            $cindex = $Index + 1
            $sCellValue = _ExcelReadCell($oExcel, $i, 1)
            $cell_net = StringStripWS($sCellValue, 3)
            If $cell_net = "Netname" Then
                $cell_net = ""
            EndIf
            ;ConsoleWrite( $cell_net & @CRLF)
            ;MsgBox(0, "", "cell_net is: " & @CRLF & $cell_net, 2)
            If StringLen($cell_net) Then
                $nlgth = FindNetinArray($cell_net)
                _ExcelWriteCell($oExcel, $nlgth, $i, 2)
            EndIf
            $Index = $Index + 1
        Next
    Else
        $oExcel = ""
        MsgBox(0, "SpreadSheet Was Not Open", "SpreadSheet Was Not Open" & @CRLF & "Open Spreadsheet, to Run a Length Check")
        ;OpenSS()
    EndIf
EndFunc

Thanks very much.

myids

Link to comment
Share on other sites

I understand your point, but I can't see exactly what AutoIt could do against that. The object handle/pointer/reference you have in AutoIt is unable to protect against the actual object being closed by magic wand acting from "above". Any method you would invoke would encounter the same "object has been destroyed" situation and cause graceless failure.

There should be a check which would stop destroying the object if created by another program/PID. But AFAIK this is the responsability of the class you instanciate, certainly not AutoIt. Perhaps a COM guru could shed some light on this as I'm on thin ice there. There is a seperate forum for COM specialized questions. Try there as well.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

Thanks.

I guess what I am looking for is one: what is the question I would need ask to the COM forum.

two: how do check if the object exists so I can handle it gracefully if it doesn't exist, instead of allowing the script to crash?

Link to comment
Share on other sites

Your one is your two!

Try to ask there how to handle gracefully a situation where an AutoIt COM object being closed unexpectedly thru the object's GUI.

As I see it, IsObj is only a method of the AutoIt variant class which returns True if the variant was created as an object type (not a string, a number, nor anything else). And I don't see how it could ensure the COM object is still "there" except if the COMM machinery has special provision for such cases. This is what I don't know and where experienced COM gurus would have their word.

Best luck.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

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