+ Reply to Thread
Results 1 to 6 of 6

check if file is in use

  1. #1
    Valued Forum Contributor
    Join Date
    03-23-2008
    Location
    Tennessee
    MS-Off Ver
    Office 2007
    Posts
    706

    check if file is in use

    Good day, Gurus.

    I have a script used by several users that copies information to a workbook stored on the network. If another user has the file open when they try to copy their data, it won't copy because the network file is opened as read only.

    What kind of error handler can I put in place to chekc if the file is in use?

    Thanks in advance.

  2. #2
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    See if links help

    http://www.xcelfiles.com/IsFileOpen.html

    http://www.ozgrid.com/VBA/IsWorkbookOpen.htm

    http://www.vbaexpress.com/kb/getarticle.php?kb_id=468

    VBA Noob
    _________________________________________


    Credo Elvem ipsum etian vivere
    _________________________________________
    A message for cross posters

    Please remember to wrap code.

    Forum Rules

    Please add to your signature if you found this link helpful. Excel links !!!

  3. #3
    Valued Forum Contributor
    Join Date
    03-23-2008
    Location
    Tennessee
    MS-Off Ver
    Office 2007
    Posts
    706
    How's it going, Noob?

    The instructions at xcelfiles.com had a fundtion to check if the file was open on the network, rather than just on the host computer, which is what I needed. I tested the macro, and it worked IF the filename was a constant. When I tried to change the filename to a variable I got an error, "Compile Error: Constant Expression Required". Then if I try to Dim the statement "strFileToOpen" to either a workbook or a string, I get the error "Complie Error: Object required."

    Here's the code as I'm trying to use it, I annotated out the oritginal code at the top.
    Please Login or Register  to view this content.
    Any suggestions on how I can modify this routine for my purposes?

  4. #4
    Valued Forum Contributor
    Join Date
    03-23-2008
    Location
    Tennessee
    MS-Off Ver
    Office 2007
    Posts
    706
    Although I would rather check if the workbook is open on the network, and never open is if it is, I haven't been able to figure out how to do that on a file with a variable filename.

    As an alternate solution, I have the following code, that opens the workbook, checks the read only status, and closes it immediately if read only is true.
    Please Login or Register  to view this content.
    The problem is, by default, the workbook opens with notification when the workbook becomes available, so when the workbook is closed the user gets a message "...Workbook is now available for editing." How can I disable this alert, so that the workbook just closes with no further activity required by the user?

    By the way, I'm still interested in not taking the time to open the workbook if it is in use, if we can find a way to do it with the variable filename used above.

    Thanks in advance!

  5. #5
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,437
    the variable is a simple string variable. No need to use the set statement

    Please Login or Register  to view this content.
    Cheers
    Andy
    www.andypope.info

  6. #6
    Valued Forum Contributor
    Join Date
    03-23-2008
    Location
    Tennessee
    MS-Off Ver
    Office 2007
    Posts
    706
    Thanks, Andy. That's all it took.

    Have a good one!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Excel 2007 error when adding custom help file to user defined function
    By sabotuer99 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-04-2009, 01:10 AM
  2. Required - macro to check whether the file is open
    By gloring in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-01-2008, 04:44 AM
  3. import data from .txt file selected by user
    By ahartman in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 02-29-2008, 03:34 AM
  4. Summarize results from files into main file
    By aktarina in forum Excel General
    Replies: 4
    Last Post: 09-06-2007, 01:09 AM
  5. unknown file name
    By khalid79m in forum Excel General
    Replies: 2
    Last Post: 03-10-2007, 10:45 AM

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