Results 1 to 6 of 6

(Main Question Answered) Check File Open with random Path

Threaded View

  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.

         Sub CheckForFile()
         Filename = "test.xls"
         FileExists = False
    
         For Each book In Workbooks
             If UCase(book.Name) = Filename Then
                 FileExists = True
             End If
         Next book
    
         UCase
         If FileExists Then _
              MsgBox Filename & " is open." Else _
                 MsgBox Filename & " is not open."
         End Sub
    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

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