Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How can I check if excel File is open before writing to
Message
General information
Forum:
Visual FoxPro
Category:
COM/DCOM and OLE Automation
Miscellaneous
Thread ID:
00812502
Message ID:
00812506
Views:
13
This message has been marked as the solution to the initial question of the thread.
Something like this:
if file(lcFileName)
 * check for exclusive access
 lnfp=fopen(lcFileName,2)  && read and write
 if lnfp>0   &&OK
    =fclose(lnfp)
 else
   * file is in use error go here
 endif
endif
>I have code that reads binary data (an embedded excel spreadsheet) from a sql server table using an ADODB.Stream. Then it writes the excel data back to the users local drive.
>
>However, if the user chooses an excel filename to save to, and that file is already open in excel, I get an Ole error.
>
>I can check for this with my error handler, and if the write fails just close the stream and tell the user that the file is already open. However, my question is, is there anyway that I can test if the file is already open, without generating an error and without using error handling code
>
>A portion of the code is below
>
> omstream.Type = adTypeBinary
> omstream.Open()
> ovalue=ors.Fields("FILECOL")
> omstream.Write(ovalue)
> omstream.SaveToFile(lcFileName, adSaveCreateOverWrite)
> omstream.close()
>
>
>TIA
Previous
Reply
Map
View

Click here to load this message in the networking platform