+ Reply to Thread
Results 1 to 11 of 11

How to know if a file (notepad) is open?

  1. #1
    Registered User
    Join Date
    11-01-2012
    Location
    helsinki, finland
    MS-Off Ver
    Excel 2007
    Posts
    81

    How to know if a file (notepad) is open?

    Hello!

    How to now if Notepad, let's say test.txt, is open or not?

    Also how to close it or any file.

    Around internet there are a lot of virtual things as close notepad with VBA,
    however, so far I haven't found any working code,
    this looks quite nice:
    Please Login or Register  to view this content.
    However, it does not open test.txt so I don't now could it close it also.

    The big question is as the title suggest, how can one know if test.txt is already open?

    regards
    keymuu
    Last edited by keymuu; 12-05-2012 at 05:30 AM.

  2. #2
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: How to know if a file (notepad) is open?

    1. Why do you actually need to open it?
    2. If the user is using notepad, why can't they close it them self?

  3. #3
    Registered User
    Join Date
    11-01-2012
    Location
    helsinki, finland
    MS-Off Ver
    Excel 2007
    Posts
    81

    Re: How to know if a file (notepad) is open?

    Hi Kyle123!

    That is an example where the main point is not to open it but to close it, even that there is also the open function.
    If a system will run automatically then there is no users at the time there.

    regards
    keymuu

  4. #4
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: How to know if a file (notepad) is open?

    But that doesn't address my question. Why do you need to open notepad in the first place? Especially if there are no users involved.

    You can read and write to text files directly with Excel without using notepad at all.

    If you want to display text, why not use a textbox? - skip notepad altogether and you have one less problem to solve

  5. #5
    Registered User
    Join Date
    11-01-2012
    Location
    helsinki, finland
    MS-Off Ver
    Excel 2007
    Posts
    81

    Re: How to know if a file (notepad) is open?

    Hi Kyle123!

    As told earlier, to open is not the issue here, it is just the close,
    the example above was just an example (with open it also).....

    It would be nice to be without Notepad, wouldn't it? However, I need it.
    I plan to use a log-file and that is the reason for the Notepad.

    If I write the log-data to the Excel, let's say a sheet called LOG or something like that,
    then the file.xlsm wouldn't be a clean log-file, like log.txt is.

    Still looking for a way to know if Notepad is open?

    regards
    keymuu

  6. #6
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: How to know if a file (notepad) is open?

    No you don't, you're complicating things by trying to use notepad. You can create text files with Excel VBA - consider:
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    10-19-2012
    Location
    Wirral, England
    MS-Off Ver
    Excel 2003
    Posts
    9

    Re: How to know if a file (notepad) is open?

    Kyle is 100% there.

    But to answer you're question, to find out if the text file is already open, you try to open it again, it will error if it's already open.

    But please don't go down the notepad route for a log file, just print to a sequential file but don't forget to close it after every entry otherwise the buffer might not be flushed to disk if something goes wrong.

  8. #8
    Registered User
    Join Date
    11-01-2012
    Location
    helsinki, finland
    MS-Off Ver
    Excel 2007
    Posts
    81

    Re: How to know if a file (notepad) is open?

    Hi DiggingDeeper and Kyle!

    Thank you for these ideas, very promising indeed.
    I will try those ideas the day after tomorrow when I
    am back...

    regards
    keymuu

  9. #9
    Registered User
    Join Date
    11-28-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    2

    Re: How to know if a file (notepad) is open?

    I'm also trying to set up a macro whereby I can take data from excel 2010 into notepad or a text file inside excel. I used the code mentioned here, but keep getting an error message on this line:

    Open sFolder & sFile For Output As #1

    Thanks for the help!

  10. #10
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: How to know if a file (notepad) is open?

    Welcome to the Forum

    Welcome to the Forum, unfortunately:

    Your post does not comply with Rule 2 of our Forum RULES. Don't post a question in the thread of another member -- start your own thread. If you feel it's particularly relevant, provide a link to the other thread. It makes sense to have a new thread for your question because a thread with numerous replies can be off putting & difficult to pick out relevant replies.

  11. #11
    Registered User
    Join Date
    11-01-2012
    Location
    helsinki, finland
    MS-Off Ver
    Excel 2007
    Posts
    81

    Re: How to know if a file (notepad) is open?

    Hi Kyle!

    It took a little bit more time to get back to this matter but
    better late than not at all

    This (your code) works alone:
    Please Login or Register  to view this content.
    But it keeps it closed and write (print) things there behind your back and
    not in front of your eyes, as copy and paste would do.
    However, that is not a big deal when you know it works very good.

    The really nice thing about it is that you can use like this:

    in the first place
    Please Login or Register  to view this content.
    then writing from here and there
    Please Login or Register  to view this content.
    and finally (can be much later as long as the program runs, here or there)
    Please Login or Register  to view this content.
    So thank you for leading me to the right track, thank you indeed

    regards
    keymuu

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1