LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default What is the test for whether a file is open?

"I don't want to burden the caller
with opening the file in the event he never has to write to it."

What does anything you do "burden" the user, why would he ever/never want to
write to it.

Determining if a text-file is open, while possible, is not always
straightforward. It depends which app has opened the file. Typically with
most text editors, even if the file is open you can 'Output' or 'Append' the
file. Notepad will not update though some others will refresh with latest
contents when reactivated. However if the file is open in say Word the code
will fail with permission denied, so you can trap for that.

In passing, wouldn't you normally want to Append the log rather than rewrite
it entirely each time.

Regards,
Peter T


"Jim Luedke" wrote in message
...
What's the test for whether a file is currently open (or closed)?

My app writes to a log file, but I don't want to burden the caller
with opening the file in the event he never has to write to it. So I
want:

Dim H As Long

Sub Log(Msg as String)
If Not IsOpen(H) then
Open LogFile For Output As #H
Print #H, FileHeader & DateTime
Print #H,
End If

Print #H, Msg
End Sub

Sub Main
Repeat
If Not Something Then
Log "Oops"
End If
Until SomethingElse
Close #H
End Sub

So what expression should "IsOpen(H)" be?

Thanks.

***



 
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
test file - is open? karmela Excel Programming 3 November 22nd 07 07:20 AM
VBA Assistance needed to test for open file in a different direct Brent E Excel Programming 4 May 2nd 07 07:19 PM
Open Test file with VBA with a changing file number Michael from Austin Excel Programming 4 October 14th 05 03:18 PM
Open file - How to test the path ? Alex St-Pierre Excel Programming 3 February 7th 05 06:36 PM
Test for Open File Aaron Excel Programming 6 January 6th 05 12:37 PM


All times are GMT +1. The time now is 08:21 AM.

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

About Us

"It's about Microsoft Excel"