• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Detect if file was opened from local or network

rolo

Member
I need to detect if the opened file was opened from local drive or from network.

Thanks!
 
Try something like below.

Code:
 Function GetDriveType(strMappedDrive As String) As String
    Dim objFso As Object
    Dim strDrive As String
    Dim d
    With CreateObject("Scripting.FileSystemObject")
        strDrive = .GetDriveName(strMappedDrive)
        On Error GoTo ErrHandle:
        Set d = .GetDrive(strDrive)
        Select Case d.DriveType
            Case 0: t = "Unknown"
            Case 1: t = "Removable"
            Case 2: t = "Fixed"
            Case 3: t = "Network"
            Case 4: t = "CD-ROM"
            Case 5: t = "RAM disk"
        End Select
    End With
    GetDriveType = t
ErrHandle:
    If Err.Number > 0 Then
        GetDriveType = "Drive not found"
    End If
End Function

Sub Test()
Dim y As String
y = Split(ThisWorkbook.Path, "\")(0)
x = GetDriveType(y)
Debug.Print x
End Sub
 
Back
Top