Results 1 to 5 of 5
  1. #1
    Silver Lounger
    Join Date
    Jul 2001
    Location
    Ottawa, Ontario, Canada
    Posts
    1,609
    Thanks
    0
    Thanked 1 Time in 1 Post

    Debugging Code (VBA\Word|2003)

    I am debugging some code and realize that I have opened some files for input or output and not closed them; either as a consequence of the code not having run to completion (crashed), or directly as a result of faulty code. My problem is that I don't know of a method to determine what files are open. For example: I can create code to determine that a given file number (#n), is open, but I have been unable to expose the pathname of #n.

    Any guidance will be greatly appreciated.

    T.I.A.
    Regards
    Don

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Debugging Code (VBA\Word|2003)

    Do you need to know which files they are? If you know the file number, you can close it, without knowing the name.

  3. #3
    Silver Lounger
    Join Date
    Jul 2001
    Location
    Ottawa, Ontario, Canada
    Posts
    1,609
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Debugging Code (VBA\Word|2003)

    <hr> If you know the file number, you can close it, without knowing the name<hr>
    I understand that; but in a large project, knowing the pathname will make it much easier to home in on the code which opened it and consequently probably failed to close it.
    Regards
    Don

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Debugging Code (VBA\Word|2003)

    VBA must keep track of which file is opened with which number, but I have no idea how to retrieve this information.

    You could write the file name and file number to a log file each time you open a file, and write the file number to the logfile when you close it.
    (But if you use the same methods for writing to the log file, you'd have to open and close it each time you want to add a line, otherwise the log file wouldn't get written...)

  5. #5
    Silver Lounger
    Join Date
    Jul 2001
    Location
    Ottawa, Ontario, Canada
    Posts
    1,609
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Debugging Code (VBA\Word|2003)

    Thanks Hans
    Regards
    Don

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •