+ Reply to Thread
Results 1 to 9 of 9

Check if file is already open...don't open if file true - https://

  1. #1
    Registered User
    Join Date
    02-18-2014
    Location
    Tampa
    MS-Off Ver
    Excel 2010
    Posts
    54

    Check if file is already open...don't open if file true - https://

    Hello everyone,

    I have a workbook (UserFile) that when opened, updates based on a file stored on a Sharepoint site (DirectoryFile). This refresh macro can be called in the workbook by the user as well. There is also a survey in the UserFile that when submitted, writes to a table in the DirectoryFile, saves and closes it. The DirectoryFile, depending on the network is only accessed for a few seconds. If the DirectoryFile is already opened by another user, whether they are an admin updating the Directory File, or someone else is submitting a survey, I do not want the user (UserFile) to be given the option to "read only" or to see who is actively using the workbook. I searched around and found this function to accomplish the task when the file is in use, but I can only get it working on a file stored locally ("C:\Desktop\DirectoryFile.xlsx") and not the https:// path I am referencing.

    The (DirectoryFile) can be read only on update/refresh but I want to make it completely unavailable if (Userfile) is submitting a survey which is a separate macro.

    Any assistance is greatly appreciated.

    -Curtis

    I was getting an error 52 when plugging in the path "https://. . . /DirectoryFile.xlsx"

    Please Login or Register  to view this content.

  2. #2
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: Check if file is already open...don't open if file true - https://

    Does this not work for you?
    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    02-18-2014
    Location
    Tampa
    MS-Off Ver
    Excel 2010
    Posts
    54

    Re: Check if file is already open...don't open if file true - https://

    Thanks for the response.

    I am not having any luck with it though. Not sure where to call it. I’ve attached a portion of my macro that will produce the “file in use” prompt.

    Please Login or Register  to view this content.

  4. #4
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,908

    Re: Check if file is already open...don't open if file true - https://

    Try this way.

    Please Login or Register  to view this content.
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  5. #5
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Check if file is already open...don't open if file true - https://

    There are two issues here which may or may not be the same:

    a. Is Workbook Open? (code from Bakerman2 in post #4). The workbook will appear to be open only if the User is using one instance of Excel and the file is open in that instance of Excel. If using multiple instances of Excel on the same computer, each instance has no knowledge of other instances (unless code exists to access other Excel instances), and if the file is open in another instance of Excel, 'Is Workbook Open' will return False.

    b. Is File Open? (code from DJDRU in post #1). The file will appear to be Open if any user on any computer has the file open (error 70 - permission denied).

    Lewis

  6. #6
    Registered User
    Join Date
    02-18-2014
    Location
    Tampa
    MS-Off Ver
    Excel 2010
    Posts
    54

    Re: Check if file is already open...don't open if file true - https://

    Quote Originally Posted by bakerman2 View Post
    Try this way.

    Please Login or Register  to view this content.
    This is still returning the file in use prompt:

    98C677E2-3705-4C05-8FE1-D23F866B2421.png

    Goal is to suppress this prompt, and disable any access, read only
    or not to this file if it’s being used elsewhere.

  7. #7
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: Check if file is already open...don't open if file true - https://

    My use would be similar to bakerman2's only I would pass the full path. Unless it is a SharePoint site, I don't see how file use could be checked. Most web sites would open as ReadOnly like dropbox and onedrive.

    I guess you can try an Application.DisplayAlerts=False but it would probably open as readonly if it worked at all.

    Please Login or Register  to view this content.

  8. #8
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Check if file is already open...don't open if file true - https://

    I have no experience with SharePoint, but I found the following code (untested) which may be applicable using:
    a. CanCheckOut (seems to be unreliable). It is recommended to use .Checkout instead, and if .Checkout fails, then the file is open to someone else.
    b. CheckOut
    c. CanCheckIn
    d. CheckIn
    Please Login or Register  to view this content.
    Lewis

  9. #9
    Registered User
    Join Date
    02-18-2014
    Location
    Tampa
    MS-Off Ver
    Excel 2010
    Posts
    54

    Re: Check if file is already open...don't open if file true - https://

    Quote Originally Posted by LJMetzger View Post
    I have no experience with SharePoint, but I found the following code (untested) which may be applicable using:
    a. CanCheckOut (seems to be unreliable). It is recommended to use .Checkout instead, and if .Checkout fails, then the file is open to someone else.
    b. CheckOut
    c. CanCheckIn
    d. CheckIn
    Please Login or Register  to view this content.
    Lewis

    Working!!!! Thank you all for the help!

    Curtis

    Please Login or Register  to view this content.

+ 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. [SOLVED] Check for existing File name, open if exist or open new workbook if not
    By COURTTROOPER in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-09-2017, 12:32 AM
  2. [SOLVED] Macro to open workbook with a suffix (need help to check if file is already open)
    By rossi_69 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-24-2017, 11:03 AM
  3. Open Https excel file giving user and password
    By jesusnpadilla in forum Hello..Introduce yourself
    Replies: 1
    Last Post: 06-17-2014, 11:10 PM
  4. Open Https excel file giving user and password
    By jesusnpadilla in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-17-2014, 12:58 PM
  5. Replies: 2
    Last Post: 01-19-2013, 09:13 AM
  6. Check if a Word File is Open and If Open Close it with Excel VBA.
    By e4excel in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-10-2012, 11:14 AM
  7. [SOLVED] open variably named file, copy/paste data into consolidation file, open next file in list
    By sllawrence1968 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-29-2012, 09:49 PM

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