Can somebody help me with this problem ..

I need to add lines to an existing Excel file. To open the file and add the
lines is no problem, but I need to check if the file is already open, so I
don't open it again. So if the file is open in Excel, I need to add lines to
the open file ofcourse.

Thanks for the help
Xavier

Re: Excel automation by Olaf

Olaf
Wed Sep 15 10:25:14 CDT 2004

Hi,

Try to open the file with FOPEN exclusively.
If you don't succeed (don't get a file handle),
the file may already be opened.

You can check if
AddBS(oExcel.ActiveWorkbook.Path)+;
oExcel.ActiveWorkbook.Name) is the file
you want to modify.

Where oExcel is your Excel object...

You can also check other open Workbooks,
see oExcel.Workbooks.count
oExcel.Workbooks[1]
to
oExcel.Workbooks[oExcel.Workbooks.count]

Bye, Olaf.



Re: Excel automation by Cindy

Cindy
Wed Sep 15 12:16:13 CDT 2004

Hi Xavier,

Look at GetObject() in Help. It's an alternative to CreateObject() that gets
a reference to a file if it's already open.

--
Cindy Winegarden MCSD, Microsoft Visual FoxPro MVP
cindy_winegarden@msn.com www.cindywinegarden.com


"Nuyttens Xavier" <xavier@cpsit.be> wrote in message
news:CxY1d.246932$yw1.12538934@phobos.telenet-ops.be...
> I need to add lines to an existing Excel file. To open the file and add
> the lines is no problem, but I need to check if the file is already open,
> so I don't open it again. So if the file is open in Excel, I need to add
> lines to the open file ofcourse.
>



Re: Excel automation by Altman

Altman
Wed Sep 15 13:51:25 CDT 2004

checkout ActiveWorkBook.ReadOnly under the session object. As long as the
file is not marked as read only, then this will be true if another person
has the file open.


"Nuyttens Xavier" <xavier@cpsit.be> wrote in message
news:CxY1d.246932$yw1.12538934@phobos.telenet-ops.be...
> Can somebody help me with this problem ..
>
> I need to add lines to an existing Excel file. To open the file and add
> the lines is no problem, but I need to check if the file is already open,
> so I don't open it again. So if the file is open in Excel, I need to add
> lines to the open file ofcourse.
>
> Thanks for the help
> Xavier
>



Re: Excel automation by Nuyttens

Nuyttens
Thu Sep 16 08:42:44 CDT 2004

thanks for the help, I was able to solve my problem combining the answers
like this :

oBook = GETOBJECT(lcFile)
WITH oBook
oExcel = .Application
.Application.Visible = .T.
ENDWITH
obook.windows(1).activate()

IF oBook.ReadOnly
&& show message 'file in use'
return
ENDIF

lcSheet = obook.Sheets(1)

"Nuyttens Xavier" <xavier@cpsit.be> schreef in bericht
news:CxY1d.246932$yw1.12538934@phobos.telenet-ops.be...
> Can somebody help me with this problem ..
>
> I need to add lines to an existing Excel file. To open the file and add
> the lines is no problem, but I need to check if the file is already open,
> so I don't open it again. So if the file is open in Excel, I need to add
> lines to the open file ofcourse.
>
> Thanks for the help
> Xavier
>