Re: Determining whether a document is open

From: Chris Morgan (chris.nospam)
Date: 01/07/04


Date: Wed, 7 Jan 2004 13:19:39 -0000


> Thanks Chris. The code worked great, and suprisingly it does
actually work
> for MS Word and Excel (2000). Unfortunately it does not work for
text files
> opened in Notepad. I guess this is probably due to the problem Iain
> Macmillan described where the app closes the disk file after loading
it into
> memory. I haven't yet tested any other apps except Word, Excel and
Notepad.
> Does anybody know of any way of determining whether a file is opened
in an
> app like Notepad, or is this simply impossible?

Glad it helped.
I doubt there is any comprehensive method that will work for all
applications.
You could try using the Window handle of Notepad and checking if the
start of
the window caption is the same as the file name, but this is really
dodgy,
and wouldn't work for programs like Internet Explorer, or other text
editors
which don't display the filename as the first part of the caption.
I think you may have to do a combination of checking whether you can
open the
file in Exclusive mode, and using WaitForSingleObject (or whatever) to
signal
when the application you called in ShellExecute terminates.

Cheers,

Chris



Relevant Pages

  • Re: Determining whether a document is open
    ... Thanks Chris. ... Macmillan described where the app closes the disk file after loading it into ... I haven't yet tested any other apps except Word, Excel and Notepad. ...
    (borland.public.delphi.language.objectpascal)
  • Re: Determining whether a document is open
    ... > for MS Word and Excel. ... > Macmillan described where the app closes the disk file after loading it ... > app like Notepad, ... using EnumWindows to check if the filename is in any window caption ...
    (borland.public.delphi.language.objectpascal)
  • Re: open excel worksheet
    ... Chris, thank you for answering, but still, ... with black sheet(when open it from my vb app) or Book1 ... sheet when open the file from Excel directly. ... >Set ObjExcel = New excel.Application ...
    (microsoft.public.vb.general.discussion)
  • RE: Starting another app from my VB app
    ... System.Diagnostics.Process.Start("Notepad") will start notepad ... System.Diagnostics.Process.Start("Excel") will start excel etc etc etc ... > to hard code the path because this app might be in a different location on ...
    (microsoft.public.dotnet.languages.vb)
  • Importing text files into Excel
    ... Excel. ... separate the data vary in number. ... tabs while in Notepad but it takes too long. ... Chris ...
    (microsoft.public.excel.misc)