who has Excel file open

froggy73

New Member
Joined
Aug 15, 2018
Messages
4
I have been trying to get this to work for last few days and cant seem to understand why. I was able to get it to work via mapped drive but I don't want to use that method. I want to use the unc path instead. It seems to work for the sub section but gets to function side and says invalid object found.

Rich (BB code):
Sub Used()




'testWorkbookLockFile = "K:\~$FileName.xlsm"
mypath = "\\IP\Folder\~$FileName.xlsm"
Set objFSO = CreateObject("Scripting.FileSystemObject")


If objFSO.FileExists(mypath) Then
    Set TxtRng = ActiveWorkbook.Sheets("Sheet1").Cells(1, 1)
   
    TxtRng.Value = "The file is locked by " & GetFileOwner(mypath)
Else
Set TxtRng = ActiveWorkbook.Sheets("Sheet1").Cells(1, 1)
    TxtRng.Value = "The file is available"
End If
End Sub


Function GetFileOwner(strFilename)
  
    Set objWMIService = GetObject("winmgmts:")
    Set objFileSecuritySettings = _                                                                       <<<
    objWMIService.Get("Win32_LogicalFileSecuritySetting='" & strFilename & "'")   <<<< says not found and only when someone has it open but the strfilename gets passed as it should
    intRetVal = objFileSecuritySettings.GetSecurityDescriptor(objSD)


    If intRetVal = 0 Then
       GetFileOwner = objSD.owner.Name
    Else
       GetFileOwner = "Unknown"
    End If






End Function
 
Last edited by a moderator:

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"

Forum statistics

Threads
1,214,630
Messages
6,120,634
Members
448,973
Latest member
ChristineC

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