Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Checking files for write-access


Hiya

I've got an application which is having some trouble because it keeps
trying to open a file to read that's still being used by another
application. In short, I have program A that writes a file and then my
script B that tries to read it. The problem is, all B does at the
moment is looks to see if it's there, not whether or not A is finished
writing to it. So B, when it sees the file, attempts to open it, and if
A is still running, B will break.

So what I'm looking for is some way to determine if a file is not only
existing, but also is ready for interactions with. I want it to check
that a file isn't being used by another application.

I imagine there's a method for it, but I can't see it anywhere.

I'm using VBA 6.3

Cheers!


--
F*SH
------------------------------------------------------------------------
F*SH's Profile: http://www.excelforum.com/member.php...o&userid=36355
View this thread: http://www.excelforum.com/showthread...hreadid=566966

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default Checking files for write-access

Assuming this is some text file rather than an Excel file, check out the
Open statement in VBA help and the lock argument.
Trap the error if "Lock Write" fails.

NickHK

"F*SH" wrote in message
...

Hiya

I've got an application which is having some trouble because it keeps
trying to open a file to read that's still being used by another
application. In short, I have program A that writes a file and then my
script B that tries to read it. The problem is, all B does at the
moment is looks to see if it's there, not whether or not A is finished
writing to it. So B, when it sees the file, attempts to open it, and if
A is still running, B will break.

So what I'm looking for is some way to determine if a file is not only
existing, but also is ready for interactions with. I want it to check
that a file isn't being used by another application.

I imagine there's a method for it, but I can't see it anywhere.

I'm using VBA 6.3

Cheers!


--
F*SH
------------------------------------------------------------------------
F*SH's Profile:

http://www.excelforum.com/member.php...o&userid=36355
View this thread: http://www.excelforum.com/showthread...hreadid=566966



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Checking files for write-access


Thanks nick - sorry it took me so long to get a chance to try your
idea!

Unfortunately, it didn't work :( or at least the way I did it didn't
work.

I wrote the following code. In the event that the file is still being
written to, the open command should fail but the error handling should
suppress this and cause the execution to jump just before the command,
to try again. Only when the the file is properly opened will the
program continue.

But it doesn't. On the first iteration, the Open command fails but the
error is not suppressed. It halts, and the user is given a "permission
denied" dialogue. The error handler did not engage at all.

I'm not so big on error handlers, so I've probably made a mistake in my
code somewhere - can anyone see it?


Code:
--------------------

If (Dir(strOutputFile) < "") Then ' Make sure a file exists

tryAgain: ' Jump back position
On Error GoTo tryAgain ' Setting the error behaviour
Open strOutputFile For Input Lock Write As #1 ' Try to open the file
Close #1
On Error GoTo 0 ' Stop this error handling
Exit Do
End If
--------------------


--
F*SH
------------------------------------------------------------------------
F*SH's Profile: http://www.excelforum.com/member.php...o&userid=36355
View this thread: http://www.excelforum.com/showthread...hreadid=566966

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Checking access to Sharepoint prior to use dalejrstwin Excel Programming 0 March 17th 06 06:09 PM
Is this right (open for write access) John Pritchard Excel Programming 0 September 21st 04 04:50 PM
checking if an access database is open from excel macro Keyur Excel Programming 0 April 16th 04 04:03 PM
write data to access Billy[_2_] Excel Programming 3 December 3rd 03 12:11 PM
Can Excel write to an Access DB? Mike[_36_] Excel Programming 1 July 29th 03 05:18 PM


All times are GMT +1. The time now is 12:30 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"