Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get username of open file

Status
Not open for further replies.

smma

Mechanical
Jun 4, 2007
24
US
Hello all! I have a macro which will search for a PDF in a directory and kill it if it exists. A problem occurs if someone else has the file open. I would like to have a msgbox pop up with the username who has the file open on our network, so the user can go and ask them to close it. Is there a way to do this? Here is what I have so far:

If VBA.Dir(OldPDF) <> "" Then
DelPDF = MsgBox("Delete the current PDF?", vbYesNo, "Question")
If DelPDF = vbYes Then
On Error Resume Next
VBA.Kill (OldPDF)
If Err.Number = 70 Then
'MsgBox with username--how to find it?
End If
ElseIf DelPDF = vbNo Then
MsgBox "<" & VBA.Dir(OldPDF) & "> retained. If not required, delete from directory."
End If
End If

Thanks!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top