+ Reply to Thread
Results 1 to 6 of 6

(Main Question Answered) Check File Open with random Path

  1. #1
    Registered User
    Join Date
    07-02-2008
    Location
    Fort Worth, TX
    Posts
    99

    Thumbs up (Main Question Answered) Check File Open with random Path

    I have an application that requires users to download a file from a location that is then imported at their execution into the application. I've done my best to counsel users to download the file to their desktop (for ease of locating) and to stick with a standard filename so that there are no errors. Some of these people just don't take direction well, will save the file wherever, or save the name inappropratly, or worse, open up multiple copies of the same file corrupting the name:
    ie: FileName.xls, FileName.xls(1), FileName1

    I'm trying to input some Error Handling to help these guys out because they panic when they recieve debug popups.

    What I'm primarily attempting to do is detect if FILENAME.xls is open.

    Please Login or Register  to view this content.
    The above snippet was from a reference material by John Walkenbach that is usually spot on, however no matter what I do, it always believes the file is closed, even when I'm staring at it on my screen.

    I also cannot just hardcode the path because some files are saved on the users local pc's and the path to their desktop or even their mydocuments is different than my own, and too many people could potentially be using the app at the same time to do different things so I can't have a single space for the imported files either.

    What I need to do is test if the Filename only is open (in its regular state), by just testing the name without the path.

    If its not, I can easily do the GetOpenFilename call to have them browse and locate the file and then open it, but this creates a second problem... if they named it different. Normally that'd be a cake, but, I need to store just the filename that is selected as its own variable publically so the application procedures can reference that for the duration of its running for that point in time.

    Last question, is there a way for the vba to automatically search the users desktop for the typical filename as a last ditch effort to utilize and open if it is not found?
    Last edited by Tirren; 10-29-2008 at 04:48 PM. Reason: Removed red font and added code tags

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259
    Hello Tirren,

    Here is a more thorough test macro to determine if a file of any kind is open.
    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

  3. #3
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689
    This function returns true if the specified workbook is open in the same instance of Excel.
    Please Login or Register  to view this content.
    The code you posted,
    Please Login or Register  to view this content.
    ... can never succeed because it's comparing an uppercase word to a lowercase one.
    Entia non sunt multiplicanda sine necessitate

  4. #4
    Registered User
    Join Date
    07-02-2008
    Location
    Fort Worth, TX
    Posts
    99
    The function works and should be usable. I've not tried functions before but have mulled them around, I guess now is better than never, and it will slim down the code a bit.

    Do you mind if I utilize your function and change the name to incorporate it into the error handler format i was using already?
    Last edited by Tirren; 10-27-2008 at 06:33 PM.

  5. #5
    Registered User
    Join Date
    07-02-2008
    Location
    Fort Worth, TX
    Posts
    99
    The code you posted,
    Please Login or Register  to view this content.
    ... can never succeed because it's comparing an uppercase word to a lowercase one.

    I obviously wasn't even paying attention, Thank you for pointing this out to me, I was so obsessed with the file being open, I didn't even see what was plain before me.

  6. #6
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689
    Do you mind if I utilize your function and change the name to incorporate it into the error handler format i was using already?
    Feel free. You never have to ask that question here.

+ 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