1. Welcome to Chandoo.org Forums. Short message for you

    Hi Guest,

    Thanks for joining Chandoo.org forums. We are here to make you awesome in Excel. Before you post your first question, please read this short introduction guide. When posting or responding to questions please remember our values at Chandoo.org are: Humility, Passion, Fun, Awesomeness, Simplicity, Sharing Remember that we have people here for whom English is not there first language and we need to allow for this in our dealings.

  2. 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


  3. 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

Discussion in 'VBA Macros' started by rolo, May 18, 2017.

  1. rolo

    rolo New Member

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

  2. vletm

    vletm Well-Known Member

    Do You know local drives?
    Ex. I don't have any local drives like from C to Z!
    but I have local drives.
  3. Chihiro

    Chihiro Well-Known Member

    Try something like below.

    Code (vb):
     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
        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
    NARAYANK991, rolo and Derek McGill like this.
  4. rolo

    rolo New Member

    Works perfect...
    Thanks Chihiro!

Share This Page