Shared workbook

Gilang

New Member
Joined
Feb 21, 2021
Messages
48
Office Version
  1. 2007
Platform
  1. Windows
I have a workbook that is turned into a data center, while the data processing excel file resides on a different computer. After each data is processed, all results are copied to the central workbook.
Can I find out that a datacenter workbook is still open on another computer with a macro message?
if possible can anyone help me with the syntax?
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
You can try this:
You just need to replace the FileToOpen value with your full filename.

VBA Code:
Sub FileOpenMsg()
    Dim FileToOpen As String
    
    FileToOpen = "C:\temp\file_to_open.xlsx"
    
    If IsFileOpen(FileToOpen) Then
        MsgBox "File is open"
    Else
        MsgBox "File is free"
    End If

End Sub

 
Function IsFileOpen(fName As String) As Boolean
    Dim ff       As Integer
    Dim 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
 
Upvote 0
Solution
Terima kasih atas solusinya, saya akan mencoba menerapkannya nanti karena untuk saat ini saya jauh dari komputer.
 
Upvote 0
Thanks for the solution, I will try to implement it later as for now I am away from the computer.
Sorry for my reply yesterday via cellphone so that it is automatically translated into Indonesian before sending.
 
Upvote 0
You can try this:
You just need to replace the FileToOpen value with your full filename.

VBA Code:
Sub FileOpenMsg()
    Dim FileToOpen As String
  
    FileToOpen = "C:\temp\file_to_open.xlsx"
  
    If IsFileOpen(FileToOpen) Then
        MsgBox "File is open"
    Else
        MsgBox "File is free"
    End If

End Sub


Function IsFileOpen(fName As String) As Boolean
    Dim ff       As Integer
    Dim 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
I've tried it, the macro runs but an error message box appears.
I am including the screenshort.
Is there anything lacking in that syntax?
Please find a solution
 

Attachments

  • File Location.jpg
    File Location.jpg
    9.5 KB · Views: 3
  • Macro berjalan.jpg
    Macro berjalan.jpg
    7.6 KB · Views: 2
  • Error.jpg
    Error.jpg
    75.2 KB · Views: 3
Upvote 0
I've tried it, the macro runs but an error message box appears.
I am including the screenshort.
Is there anything lacking in that syntax?
Please find a solution
The macro needs the full path and file name of the file you are trying to check.
Unless you have defined what Hosting means (eg Hosting = "FilePath\Filename"), the macro has no idea what this is.

Based on the screen shot "File Location", I think you are going to find checking the file is not going to be a simple matter.
You indicated you wanted to check a file at the data center, however the File Location given is a OneDrive file and the address is the file on someone's C drive.
This is a copy of the server file on an individual's computer. I don't think you will be able to access that nor will it tell you if the server copy is open.

If you can get the full server FilePath & FIleName you could try that but accessing OneDrive & Sharepoint files is particularly challenging.
If its a standard Network stored file then the function should work as long as you have to full name.
 
Upvote 0
The macro needs the full path and file name of the file you are trying to check.
Unless you have defined what Hosting means (eg Hosting = "FilePath\Filename"), the macro has no idea what this is.

Based on the screen shot "File Location", I think you are going to find checking the file is not going to be a simple matter.
You indicated you wanted to check a file at the data center, however the File Location given is a OneDrive file and the address is the file on someone's C drive.
This is a copy of the server file on an individual's computer. I don't think you will be able to access that nor will it tell you if the server copy is open.

If you can get the full server FilePath & FIleName you could try that but accessing OneDrive & Sharepoint files is particularly challenging.
If its a standard Network stored file then the function should work as long as you have to full name.
I have a problem changing the Err syntax but it immediately changes to ERR, please give me a solution
 

Attachments

  • Err.jpg
    Err.jpg
    45.8 KB · Views: 8
Upvote 0

Forum statistics

Threads
1,215,407
Messages
6,124,723
Members
449,184
Latest member
COrmerod

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top