Alaska Software Inc. - Connecting to Excel
Username: Password:
AuthorTopic: Connecting to Excel
Peter Alderliesten Connecting to Excel
on Thu, 05 Aug 2010 16:40:45 +0200
Hi,

I am experimenting a bit with Excel and I run into a problem that I cannot
understand.
I have created a sample (attached) that opens an Excel file and then waits
till that file is saved. If you just press the save button, all's well and
the application quits normally. As soon as I start modifying the worksheet
an error crops up, even when the document is not saved yet.

Does anyboy have a clue why this does happen this way?

Thanks a lot.

Peter


test.prg
Test.zip
J.A. Diego KerejetaRe: Connecting to Excel
on Fri, 06 Aug 2010 12:50:46 +0200
Hi Peter:

> I am experimenting a bit with Excel and I run into a problem that I cannot
> understand.
> I have created a sample (attached) that opens an Excel file and then waits
> till that file is saved. If you just press the save button, all's well and
> the application quits normally. As soon as I start modifying the worksheet
> an error crops up, even when the document is not saved yet.
>

You can not use that condition in the loop, because oDoc:saved  is
referencing an object that does not exist when the user closes the document.

Regards. Diego
Peter Alderliesten Re: Connecting to Excel
on Sat, 07 Aug 2010 10:37:14 +0200
Diego,

>> I am experimenting a bit with Excel and I run into a problem that I cannot
>> understand.
>> I have created a sample (attached) that opens an Excel file and then waits
>> till that file is saved. If you just press the save button, all's well and
>> the application quits normally. As soon as I start modifying the worksheet
>> an error crops up, even when the document is not saved yet.
>>
> 
> You can not use that condition in the loop, because oDoc:saved  is
> referencing an object that does not exist when the user closes the document.

I did not get a chance to save the document. Any key press in the document
results into an error.

Peter
J.A. Diego KerejetaRe: Connecting to Excel
on Sat, 07 Aug 2010 23:03:48 +0200
Hi Peter:

I am sorry to insist, but you can not use oDoc:saved in the loop.

If you do not make any changes and close the document will fail in the 
absence of the object referenced by oDoc.

As soon as you make any change to the document, the loop ends and the 
oExcel:destroy() code is executed.

Regards. Diego
Peter Alderliesten Re: Connecting to Excel
on Mon, 09 Aug 2010 09:47:42 +0200
Diego,

> I am sorry to insist, but you can not use oDoc:saved in the loop.
> 
> If you do not make any changes and close the document will fail in the 
> absence of the object referenced by oDoc.
> 
> As soon as you make any change to the document, the loop ends and the 
> oExcel:destroy() code is executed.

The loop should only end when the document is saved (not talking about
closing, just saving). Long before the document can be saved the
application runs into an error: with the first keystroke to modify the
document.

BTW I'm not arguing that this sample shows a sound solution, but just
questioning why the communication with Excel is not happening as you would
expect.

Peter
J.A. Diego KerejetaRe: Connecting to Excel
on Mon, 09 Aug 2010 11:09:11 +0200
Hi Peter:

> The loop should only end when the document is saved (not talking about
> closing, just saving). Long before the document can be saved the
> application runs into an error: with the first keystroke to modify the
> document.
>
> BTW I'm not arguing that this sample shows a sound solution, but just
> questioning why the communication with Excel is not happening as you would
> expect.

By design, when you try to run code (i.e., access to saved property) while 
you are in "Excel edit mode" (when a cell is accepting input), an Excepcion 
is thrown.

Regards. Diego
Peter Alderliesten Re: Connecting to Excel
on Mon, 09 Aug 2010 17:37:26 +0200
Diego,

>> The loop should only end when the document is saved (not talking about
>> closing, just saving). Long before the document can be saved the
>> application runs into an error: with the first keystroke to modify the
>> document.
>>
>> BTW I'm not arguing that this sample shows a sound solution, but just
>> questioning why the communication with Excel is not happening as you would
>> expect.
> 
> By design, when you try to run code (i.e., access to saved property) while 
> you are in "Excel edit mode" (when a cell is accepting input), an Excepcion 
> is thrown.

OK, thanks.
I'll keep this in mind and will try and avoid it.

Peter
J.A. Diego KerejetaRe: Connecting to Excel
on Mon, 09 Aug 2010 18:42:27 +0200
Peter,

>
> OK, thanks.
> I'll keep this in mind and will try and avoid it.

You can process the Excel events (i.e: workbookBeforeSave ).

Regards. Diego

PS: In one of our programs we process the event to enable the LOG system to
control access and modification of documents.


   INLINE METHOD CreateOfficeObject( cProgId, cMsjError, oProceso )
   ****************************************************************
      LOCAL oOffice := CreateObject( cProgId )

      IF Empty( oOffice )
         oProceso:destroy()
         MessageBeep( MB_ICONHAND )
         HazMensaje( ::oDlgOwner, cMsjError, { BOT_CANCEL },
XBPSTATIC_SYSICON_ICONINFORMATION, TIT_AVISO,,,, { ICON_CANCEL },
TEMPORIZACION_STD )
         ::nInicializado:= 0
         Sleep( 20 )          20 más que el tiempo marcado en el bucle del
lanzador de documentos del editor
         ::quit()             lo otros 20 están dentro del método quit
      ENDIF
      oProceso:progress:increment( 2 )
      oOffice:= oOffice:dynamicCast( ActiveXObject() )
   RETURN oOffice


   INLINE METHOD execute
   *********************

.........


               IF ::lReadOnly
                  oExcel:workbookBeforeSave := {|lCancel, lSaveAsUi, oWb|
oWb:saved:= .T., lSaveAsUi:= .F., lCancel:= .T., oWb:destroy() }
                  oExcel:workbookBeforeClose:= {|lCancel, oWb| oWb:saved:=
.T., oWb:destroy() }
               ELSE
                  oExcel:workbookBeforeSave:= {|lCancel, lSaveAsUi, oWb|
IIF( oWb:saved, nil, M->oLog:addReg( LG_SUC_DOC_EDITADO, ::cNomFile + ', ' +
::cNombre ) ), oWb:destroy() }
               ENDIF

               ::doWhile( oExcel, oExcel:workbookBeforeSave, 
oExcel:workbookBeforeClose, nil )


..........
Jorge LRe: Connecting to Excel
on Fri, 06 Aug 2010 13:04:59 -0300
Hi
i use   oBook:SaveAs( cName, 1 )


"Peter Alderliesten" <p.alderliesten@solvention.nl> escribió en el mensaje 
de noticias:tx7g3ywck37u$.19lg85e3fj4sy$.dlg@40tude.net...
> Hi,
>
> I am experimenting a bit with Excel and I run into a problem that I cannot
> understand.
> I have created a sample (attached) that opens an Excel file and then waits
> till that file is saved. If you just press the save button, all's well and
> the application quits normally. As soon as I start modifying the worksheet
> an error crops up, even when the document is not saved yet.
>
> Does anyboy have a clue why this does happen this way?
>
> Thanks a lot.
>
> Peter
AUGE_OHRRe: Connecting to Excel
on Mon, 09 Aug 2010 18:35:20 +0200
hi,

as i can say, you have open Workbook, but not activate Worksheet ?!

greetings by OHR
Jimmy