+ Reply to Thread
Results 1 to 11 of 11

"File In Use" Message - how can this be disabled?

Hybrid View

  1. #1
    Registered User
    Join Date
    07-20-2016
    Location
    UK
    MS-Off Ver
    2010
    Posts
    11

    "File In Use" Message - how can this be disabled?

    From 1 specific excel file, I have a button which opens another excel file, however I only want it to open the other excel file if it is not already opened by someone else.

    The below code works really well, except that Excel displays a "File In Use" message which offers the user 3 options: "Readonly","Notify","Cancel".
    This message is displayed immediately after the Workbooks.Open command.
    I don't want the user to see that message, because my vba will make the decision for them.
    But how can I get excel to not show that message?

    Sub Check_if_open()
    Dim LogFile As Workbook
    Dim OpenAttempt As Long
    
    Application.ScreenUpdating = False
    Application.DisplayAlerts = False
    
    ReadOnlyReOpen:
        Workbooks.Open Filename:="C:\Folder Location\File to open.xlsx"
        Windows("File to open.xlsx").Activate
        Set LogFile = ActiveWorkbook
        If LogFile.ReadOnly Then
            LogFile.Close
            Debug.Print OpenAttempt
            If OpenAttempt <= 5 Then
                OpenAttempt = OpenAttempt + 1
                GoTo ReadOnlyReOpen
                Else
                    MsgBox "Log File is opened by someone else. Please try again in a bit."
                    Application.ScreenUpdating = True
                    Application.DisplayAlerts = True
                    Exit Sub
            End If
        End If
    
    MsgBox "Log File is open."
    
    End Sub
    Last edited by seaside_escape; 07-22-2016 at 06:32 AM. Reason: Issue now solved

  2. #2
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: "File In Use" Message - how can this be disabled?

    Hi seaside,

    Welcome to the Forum!


    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE] [/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  3. #3
    Registered User
    Join Date
    07-20-2016
    Location
    UK
    MS-Off Ver
    2010
    Posts
    11

    Re: "File In Use" Message - how can this be disabled?

    Thank you, I have now added the # around the code - will people be able to see my post?

  4. #4
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: "File In Use" Message - how can this be disabled?

    Hi seaside,

    Sure, your post is just fine now!

    And, thanks for the rep!

  5. #5
    Valued Forum Contributor
    Join Date
    05-11-2013
    Location
    Wales
    MS-Off Ver
    Excel 2010
    Posts
    586

    Re: "File In Use" Message - how can this be disabled?

    Hi seaside,

    I have used the following on shared files.

    Private Sub Workbook_Open()
            
    If ActiveWorkbook.ReadOnly Then                                         'Prevents access to a network folder if already open
            MsgBox "File is Read-only and will now close"
            ThisWorkbook.Close Saved = False
        Else
            MsgBox "OK to use this file"
        End If
    
    End Sub
    Perhaps you could add it to your code.

    Regards

    peterrc

  6. #6
    Registered User
    Join Date
    07-20-2016
    Location
    UK
    MS-Off Ver
    2010
    Posts
    11

    Re: "File In Use" Message - how can this be disabled?

    Hi peterrc,
    I tried putting the workbook_open sub into the source file and I still got the "File In Use" notification when I tried opening it from another excel workbook.

  7. #7
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,338

    Re: "File In Use" Message - how can this be disabled?

    Take a look at this one.
    Function BookOpen(wbName As String) As Boolean
    Dim wb As Workbook
    On Error Resume Next
    Set wb = Workbooks(wbName)
    BookOpen = Not (Err.Number > 0)
    End Function
    
    Sub tst()
    If Not BookOpen("File to open") Then Workbooks.Open "C:\Folder Location\File to open.xlsx"
    End Sub
    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.

  8. #8
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: "File In Use" Message - how can this be disabled?


  9. #9
    Registered User
    Join Date
    07-20-2016
    Location
    UK
    MS-Off Ver
    2010
    Posts
    11

    Re: "File In Use" Message - how can this be disabled?

    Hi everyone,
    Thank you for your tips. I have tried them all but I'm still getting the "File In Use" notification.
    However, I have found the cause of the problem - but I'm still after any advice if you have some?

    In my excel workbook I have got an ActiveX Control Button ("Forms.CommandButton.1") which calls my vba code through the below:
    Private Sub SubmitAssessment_Click()
    'Application.Run "SubmitAssessment.Submit_Assessment"
    Application.Run "SubmitAssessment.tst"
    End Sub
    This is causing excel to display the "File In Use" notification.
    If I add in a Form Control Button instead, this is assigned to the Macro directly "Submit_Assessment" and it doesn't display the "File In Use" notification.

    My problem now is how do I assign a private sub macro to a Form Control Button?

  10. #10
    Valued Forum Contributor
    Join Date
    05-11-2013
    Location
    Wales
    MS-Off Ver
    Excel 2010
    Posts
    586

    Re: "File In Use" Message - how can this be disabled?

    Hi seaside,

    I have just tried to access one of my network files that I know is already being used by another member of staff.
    Yes, I was allowed to select "Read Only" but as soon as I did another massage pops up "File is read only and will now close" and the only option is to click "OK".
    In your first post you stated:-
    I only want to open an excel file if it is not already opened by someone else.
    The code I sent you doesn't allow them to open it if it is already opened - problem solved ?

    Regards

    peterrc

  11. #11
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: "File In Use" Message - how can this be disabled?

    How did you try?
    Just an example
    Sub test()
        Dim fn As String, wb As Workbook
        fn = Application.GetOpenFilename("ExcelWorkBook,*.xls")
        If fn = "False" Then Exit Sub
        If Not IsFileOpen(fn) Then
            Set wb = Workbooks.Open(fn)
        Else
            For Each wb In Workbooks
                If wb.FullName = fn Then
                    Set wb = wb: Exit For
                End If
            Next
        End If
        If wb Is Nothing Then
            MsgBox fn & " is in use"
            Exit Sub
        End If
        MsgBox wb.FullName & " is open now"
    End Sub
    
    Function IsFileOpen(fName As String) As Boolean
        Dim ff As Integer, errNum As Integer
        On Error Resume Next
        ff = FreeFile
        Open fName For Input Lock Read As #ff
        Close ff
        errNum = Err
        On Error GoTo 0
        IsFileOpen = (errNum <> 0)
    End Function

+ 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] Excel 2010 -- "Visual Basic" "Macros" and "Record Macro" all disabled.
    By NicholasL in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-07-2017, 06:11 AM
  2. Replies: 7
    Last Post: 11-14-2013, 04:25 PM
  3. MSoffice Outlook 2003 message to be saved in C dir with the file name "From" "Sent" "Sub"
    By shailendra0509 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-09-2012, 01:32 AM
  4. Transfert cell values from file "A" to file "B" skipping columns in file "B".
    By Sentrosi in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-16-2009, 11:11 PM
  5. Replies: 1
    Last Post: 03-29-2006, 09:15 AM
  6. Replies: 2
    Last Post: 10-15-2005, 10:05 AM
  7. Replies: 0
    Last Post: 10-12-2005, 12:05 PM
  8. [SOLVED] Excel sort option disabled--file name followed by "group" at top .
    By Margaret in forum Excel General
    Replies: 1
    Last Post: 04-07-2005, 12:06 PM

Tags for this Thread

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